Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QProcess - Processing output in asynchronous signals



  • I use a QProcess object along with the asynchronous signals to process data continously. I start my QProcess using start and when readyReadStandardOutput 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
    });
    
    }
    


  • @Nubcake execute the "Length processing" in another thread



  • @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.



  • @Nubcake No, QProcess does not block anything, what blocks is the processing (the "Length processing") that you do of the output. That part run it in a new thread using QtConcurrent.


Log in to reply