QProcess output example
#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(); | |
} |
#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"; | |
} | |
#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