zodd
22nd January 2019, 14:18
Hello,
I use several QProcess to start several daemons on Linux Os and "capture" there output in a slot when the signal readyRead() is emit by the QProcess.
But sometimes there is a large amount of "payload" on the differents ouputs and some output datas seems to be lost.
So to remedy to this issue, I use a thread with an infinite loop for each QProcess and it's seems to work, but I heard about the use of QEventLoop and maybe it could be a better solution :
http://doc.qt.io/qt-5/qeventloop.html
but I don't find any simple example that I'm able to understand and implement QProcess with it..
In summary, I would like to be sure that' I don't miss any data ouput on something like that:
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
(...)
QString programFoo = "sh";
QStringList argumentsFoo;
argumentsFoo << "-c" << "./myFood";
myDaemonFoo->start(programFoo, argumentsFoo);
connect(myDaemonFoo, SIGNAL(readyRead()), this, SLOT(readDaemonFooOutput()));
QString programBar = "sh";
QStringList argumentsBar;
argumentsBar << "-c" << "./myBard";
myDaemonBar->start(programBar, argumentsBar);
connect(myDaemonBar, SIGNAL(readyRead()), this, SLOT(readDaemonBarOutput()));
}
void MainWindow::readDaemonFooOutput()
{
//display output in QtextEdit
}
void MainWindow::readDaemonBAROutput()
{
//display output in QtextEdit
}
My problem with using QThreads, is that I have to emit the result from the secondary thread to the main windows thread or/and I have to protect datas with a Qmutex and I'm afraid that I can still miss some data output from the daemon.
If someone can help me or give me some advices,
Thank you.
I use several QProcess to start several daemons on Linux Os and "capture" there output in a slot when the signal readyRead() is emit by the QProcess.
But sometimes there is a large amount of "payload" on the differents ouputs and some output datas seems to be lost.
So to remedy to this issue, I use a thread with an infinite loop for each QProcess and it's seems to work, but I heard about the use of QEventLoop and maybe it could be a better solution :
http://doc.qt.io/qt-5/qeventloop.html
but I don't find any simple example that I'm able to understand and implement QProcess with it..
In summary, I would like to be sure that' I don't miss any data ouput on something like that:
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
(...)
QString programFoo = "sh";
QStringList argumentsFoo;
argumentsFoo << "-c" << "./myFood";
myDaemonFoo->start(programFoo, argumentsFoo);
connect(myDaemonFoo, SIGNAL(readyRead()), this, SLOT(readDaemonFooOutput()));
QString programBar = "sh";
QStringList argumentsBar;
argumentsBar << "-c" << "./myBard";
myDaemonBar->start(programBar, argumentsBar);
connect(myDaemonBar, SIGNAL(readyRead()), this, SLOT(readDaemonBarOutput()));
}
void MainWindow::readDaemonFooOutput()
{
//display output in QtextEdit
}
void MainWindow::readDaemonBAROutput()
{
//display output in QtextEdit
}
My problem with using QThreads, is that I have to emit the result from the secondary thread to the main windows thread or/and I have to protect datas with a Qmutex and I'm afraid that I can still miss some data output from the daemon.
If someone can help me or give me some advices,
Thank you.