class SChecker : public QProcess{ Q_OBJECT public : SChecker (QObject *parent=0); QString procName, argList; QProcess *p; private slots: void pilotStarted(); void monitorStdout(); void pilotExited(); void pilotStateChanged(QProcess::ProcessState newState); void pilotError (QProcess::ProcessError error); signals: virtual void stateChanged (QProcess::ProcessState newState); virtual void readyReadStandardOutput (); virtual void error (QProcess::ProcessError error); void pilotReady(); }; SChecker::SChecker(QObject *parent) :QProcess(){ QStringList arguments; arguments << "/"; p = new QProcess (); connect( p, SIGNAL(started()), this, SLOT(pilotStarted()) ); connect( p, SIGNAL(readyReadStandardOutput ()), this, SLOT(monitorStdout()) ); connect( p, SIGNAL(error (QProcess::ProcessError)), this, SLOT(pilotError (QProcess::ProcessError)) ); connect( p, SIGNAL(stateChanged(QProcess::ProcessState)), this, SLOT(pilotStateChanged(QProcess::ProcessState)) ); p->start("/bin/df", arguments); //так стартует, правда нет вывода в консоль p->start(this->procName, arguments); //так не стартует, переменная procName почему-то пустая qDebug("PROCESS NAME : %s", this->procName.toLocal8Bit().constData()); //выводит пустую строку}void SChecker::monitorStdout(){ QByteArray output; qDebug("Ready"); output = readAllStandardOutput (); qDebug() << output;}int main(int argc, char *argv[]) { QApplication app(argc, argv); MyWidget widget; SChecker *proc = new SChecker; proc->procName = "/bin/df"; widget.show(); return app.exec(); }
C++ (Qt)void SChecker::monitorStdout(){ QByteArray output; qDebug("Ready"); output = p->readAllStandardOutput (); // <----- qDebug() << output; }
class SChecker : public QProcess{ Q_OBJECT public : SChecker (QObject *parent=0, QString procName=0); QProcess *p; private slots: void pilotStarted(); void monitorStdout(); void pilotExited(); void pilotStateChanged(QProcess::ProcessState newState); void pilotError (QProcess::ProcessError error); signals: virtual void stateChanged (QProcess::ProcessState newState); virtual void readyReadStandardOutput (); virtual void error (QProcess::ProcessError error); void pilotReady(); };SChecker::SChecker(QObject *parent, QString procName) :QProcess(){ QStringList arguments; arguments << "/"; p = new QProcess (); connect( p, SIGNAL(started()), this, SLOT(pilotStarted()) ); connect( p, SIGNAL(readyReadStandardOutput ()), this, SLOT(monitorStdout()) ); connect( p, SIGNAL(error (QProcess::ProcessError)), this, SLOT(pilotError (QProcess::ProcessError)) ); connect( p, SIGNAL(stateChanged(QProcess::ProcessState)), this, SLOT(pilotStateChanged(QProcess::ProcessState)) ); p->start(procName, arguments); qDebug("PROCESS NAME : %s", procName.toLocal8Bit().constData());}void SChecker::monitorStdout(){ QByteArray output; qDebug("Ready"); output = readAllStandardOutput (); qDebug() << output;}void SChecker::pilotStateChanged(ProcessState newState){ qDebug("Process State code: %d", newState);}void SChecker::pilotError(ProcessError error){ qDebug("Error code: %d", error);} int main(int argc, char *argv[]) { QApplication app(argc, argv); MyWidget widget; SChecker *proc = new SChecker(0, "/bin/df"); widget.show(); return app.exec(); }
C++ (Qt)class SChecker : public QObject{ Q_OBJECT...};
C++ (Qt)SChecker::SChecker(){... p = new QProcess ();...}