Created
December 27, 2013 15:14
-
-
Save ynonp/8148340 to your computer and use it in GitHub Desktop.
QProcess output example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <QCoreApplication> | |
#include <QtCore/QtCore> | |
#include "monitor.h" | |
int main(int argc, char *argv[]) | |
{ | |
QCoreApplication a(argc, argv); | |
QProcess p; | |
p.start("/bin/ls"); | |
qDebug() << "Let's Go"; | |
Monitor m; | |
QObject::connect(&p, SIGNAL(finished(int,QProcess::ExitStatus)), &m, SLOT(finished(int,QProcess::ExitStatus))); | |
QObject::connect(&p, SIGNAL(readyReadStandardOutput()), &m, SLOT(readyReadStandardOutput())); | |
QObject::connect(&p, SIGNAL(started()), &m, SLOT(started())); | |
return a.exec(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "monitor.h" | |
#include <QtCore/QtCore> | |
#include <QProcess> | |
Monitor::Monitor(QObject *parent) : | |
QObject(parent) | |
{ | |
} | |
void Monitor::error(QProcess::ProcessError error) | |
{ | |
qDebug() << "Error: " << error; | |
} | |
void Monitor::finished(int exitCode, QProcess::ExitStatus exitStatus) | |
{ | |
qDebug() << "Finished: " << exitCode; | |
qApp->exit(); | |
} | |
void Monitor::readyReadStandardError() | |
{ | |
qDebug() << "ReadyError"; | |
} | |
void Monitor::readyReadStandardOutput() | |
{ | |
qDebug() << "readyOut"; | |
QProcess *p = (QProcess *)sender(); | |
QByteArray buf = p->readAllStandardOutput(); | |
qDebug() << buf; | |
} | |
void Monitor::started() | |
{ | |
qDebug() << "Proc Started"; | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef MONITOR_H | |
#define MONITOR_H | |
#include <QObject> | |
#include <QtCore/QtCore> | |
class Monitor : public QObject | |
{ | |
Q_OBJECT | |
public: | |
explicit Monitor(QObject *parent = 0); | |
signals: | |
public slots: | |
void error(QProcess::ProcessError error); | |
void finished(int exitCode, QProcess::ExitStatus exitStatus); | |
void readyReadStandardError(); | |
void readyReadStandardOutput(); | |
void started(); | |
}; | |
#endif // MONITOR_H |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment