Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QProcess - Processing output in asynchronous signals
Forum Updated to NodeBB v4.3 + New Features

QProcess - Processing output in asynchronous signals

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 975 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Nubcake
    wrote on last edited by
    #1

    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
    });
    
    }
    
    eyllanescE 1 Reply Last reply
    0
    • N Nubcake

      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
      });
      
      }
      
      eyllanescE Offline
      eyllanescE Offline
      eyllanesc
      wrote on last edited by
      #2

      @Nubcake execute the "Length processing" in another thread

      If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

      1 Reply Last reply
      2
      • N Offline
        N Offline
        Nubcake
        wrote on last edited by Nubcake
        #3

        @eyllanesc Do you mean run QProcess inside a QThread and use the synchronous signals instead?

        eyllanescE 1 Reply Last reply
        0
        • nageshN Offline
          nageshN Offline
          nagesh
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0
          • N Nubcake

            @eyllanesc Do you mean run QProcess inside a QThread and use the synchronous signals instead?

            eyllanescE Offline
            eyllanescE Offline
            eyllanesc
            wrote on last edited by eyllanesc
            #5

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

            If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

            1 Reply Last reply
            1

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved