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 996 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 13 Mar 2021, 23:38 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
    });
    
    }
    
    E 1 Reply Last reply 13 Mar 2021, 23:48
    0
    • N Nubcake
      13 Mar 2021, 23:38

      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
      });
      
      }
      
      E Offline
      E Offline
      eyllanesc
      wrote on 13 Mar 2021, 23:48 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 13 Mar 2021, 23:57 last edited by Nubcake
        #3

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

        E 1 Reply Last reply 14 Mar 2021, 02:01
        0
        • N Offline
          N Offline
          nagesh
          wrote on 14 Mar 2021, 00:03 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
            13 Mar 2021, 23:57

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

            E Offline
            E Offline
            eyllanesc
            wrote on 14 Mar 2021, 02:01 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

            5/5

            14 Mar 2021, 02:01

            • Login

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