#include <QCoreApplication>
#include <QProcess>
#include <QDebug>
#include <QTimer>
class process_handler
: public QObject{
Q_OBJECT
public:
process_handler() {
connect(&p,
SIGNAL(stateChanged
(QProcess::ProcessState)),
this,
SLOT(process_state_changed
(QProcess::ProcessState)));
connect(&p,
SIGNAL(finished
(int,
QProcess::ExitStatus)),
this,
SLOT(process_finished
(int,
QProcess::ExitStatus)));
start_process();
}
public slots:
void process_state_changed
(QProcess::ProcessState state
) { qDebug() << "Process is starting up...";
qDebug() << "Process is now running." ;
qDebug() << "Process is finished running.";
start_process();
//QTimer::singleShot(0, this, SLOT(start_process()));
}
}
void process_finished
(int ,
QProcess::ExitStatus ){ qDebug() << "received finished signal";
}
void start_process() {
p.start("ping 1.1.1.1 -c 1 -W 3"); // from your previous thread
}
private:
};
int main(int argc, char *argv[]) {
process_handler ph;
app.exec();
}
#include "main.moc"
#include <QCoreApplication>
#include <QProcess>
#include <QDebug>
#include <QTimer>
class process_handler : public QObject
{
Q_OBJECT
public:
process_handler() {
connect(&p, SIGNAL(stateChanged(QProcess::ProcessState)), this, SLOT(process_state_changed(QProcess::ProcessState)));
connect(&p, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(process_finished(int, QProcess::ExitStatus)));
start_process();
}
public slots:
void process_state_changed(QProcess::ProcessState state) {
if (state == QProcess::Starting)
qDebug() << "Process is starting up...";
if (state == QProcess::Running)
qDebug() << "Process is now running." ;
if (state == QProcess::NotRunning){
qDebug() << "Process is finished running.";
start_process();
//QTimer::singleShot(0, this, SLOT(start_process()));
}
}
void process_finished(int , QProcess::ExitStatus ){
qDebug() << "received finished signal";
}
void start_process() {
p.start("ping 1.1.1.1 -c 1 -W 3"); // from your previous thread
}
private:
QProcess p;
};
int main(int argc, char *argv[]) {
QCoreApplication app(argc, argv);
process_handler ph;
app.exec();
}
#include "main.moc"
To copy to clipboard, switch view to plain text mode
The output on my box is:
Bookmarks