QProcess - Processing output in asynchronous signals
-
I use a
QProcess
object along with the asynchronous signals to process data continously. I start my QProcess usingstart
and whenreadyReadStandardOutput
is received, I do lengthy processing inside the associated slot but I've noticed that this causes the GUI to hang/block during this processing.How can I process data without blocking the GUI when I get the
readyReadStandardOutput
signal?Some psuedocode
Task task; task.asyncProcess(); void Task::asyncProcess() { m_process.setProgram("task.exe"); m_process.start(); ... QObject::connect(&m_process, &QProcess::readyReadStandardOutput, this, [this]() { // Length processing in here which causes GUI to block }); }
-
@eyllanesc Do you mean run QProcess inside a QThread and use the synchronous signals instead?
-
@Nubcake at present "lengthy processing" is done in the main/GUI thread context.
Which is causing the GUI to block. Offload the processing part to another thread as suggested by @eyllanesc.create the new thread instance and move the "task" object to that thread using moveToThread.