Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QProcess is blocking UI and destroyed while app running
Qt 6.12 LTS is out! See what's new in the release blog

QProcess is blocking UI and destroyed while app running

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 2.1k Views 1 Watching
  • 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.
  • K Offline
    K Offline
    KejPi
    wrote on last edited by
    #1

    Hello All,

    I am facing strange issues with QProcess (Qt 5.12.12) on MacOS and Linux. I am running long process (DFU programming) that takes about 10-15 seconds to complete. I have actually 2 problems:

    • Application UI stops responding while process is running
    • When the process finishes I get this message
    (0): QProcess: Destroyed while process ("/Applications/STMicroelectronics/STM32CubeProgrammer/STM32CubeProgrammer.app/Contents/MacOs/bin/STM32_Programmer_CLI") is still running.
    

    The class and thus QProcess instance is destroyed when application exits.

    I do not know if this is relevant but process is started from timer timeout slot when DFU device is detected, I do not wait for a process to finish, I rely on finished signal. My assumption was that the process runs separately from main window thread and thus is should not block anything. It seems that these issues are not existing on Windows, only on MacOS and Linux.

    Although these issues are happening, it seems that the process finishes correctly with exist status QProcess::NormalExit

    Releavant pieces of the code:

    // header
    class DfuProgramming : public QObject
    {
        Q_OBJECT
        // ....
    private:
       QProcess m_dfuProcess;
       QTimer * m_detectDfuTimer;
    }
    
    // source
    DfuProgramming::DfuProgramming(QObject *parent) : QObject(parent)
    {
        // ...
        connect(&m_dfuProcess, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), this, &DfuProgramming::dfuFinishedSlot);
        connect(m_detectDfuTimer, &QTimer::timeout, this, &DfuProgramming::dfuEvent);
        //...
    }
    
    void DfuProgramming::dfuEvent()
    {
        //...
        m_dfuProcess.start(cmd);
    }
    

    What am I doing wrong? Is there any principal issue?

    Christian EhrlicherC JonBJ 2 Replies Last reply
    0
    • K KejPi

      Hello All,

      I am facing strange issues with QProcess (Qt 5.12.12) on MacOS and Linux. I am running long process (DFU programming) that takes about 10-15 seconds to complete. I have actually 2 problems:

      • Application UI stops responding while process is running
      • When the process finishes I get this message
      (0): QProcess: Destroyed while process ("/Applications/STMicroelectronics/STM32CubeProgrammer/STM32CubeProgrammer.app/Contents/MacOs/bin/STM32_Programmer_CLI") is still running.
      

      The class and thus QProcess instance is destroyed when application exits.

      I do not know if this is relevant but process is started from timer timeout slot when DFU device is detected, I do not wait for a process to finish, I rely on finished signal. My assumption was that the process runs separately from main window thread and thus is should not block anything. It seems that these issues are not existing on Windows, only on MacOS and Linux.

      Although these issues are happening, it seems that the process finishes correctly with exist status QProcess::NormalExit

      Releavant pieces of the code:

      // header
      class DfuProgramming : public QObject
      {
          Q_OBJECT
          // ....
      private:
         QProcess m_dfuProcess;
         QTimer * m_detectDfuTimer;
      }
      
      // source
      DfuProgramming::DfuProgramming(QObject *parent) : QObject(parent)
      {
          // ...
          connect(&m_dfuProcess, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), this, &DfuProgramming::dfuFinishedSlot);
          connect(m_detectDfuTimer, &QTimer::timeout, this, &DfuProgramming::dfuEvent);
          //...
      }
      
      void DfuProgramming::dfuEvent()
      {
          //...
          m_dfuProcess.start(cmd);
      }
      

      What am I doing wrong? Is there any principal issue?

      Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Please use a debugger to see where exactly the program is blocking. I doubt it's during start().
      Also make sure the timer is a single shot timer so the slot is only called once.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      K 1 Reply Last reply
      1
      • K KejPi

        Hello All,

        I am facing strange issues with QProcess (Qt 5.12.12) on MacOS and Linux. I am running long process (DFU programming) that takes about 10-15 seconds to complete. I have actually 2 problems:

        • Application UI stops responding while process is running
        • When the process finishes I get this message
        (0): QProcess: Destroyed while process ("/Applications/STMicroelectronics/STM32CubeProgrammer/STM32CubeProgrammer.app/Contents/MacOs/bin/STM32_Programmer_CLI") is still running.
        

        The class and thus QProcess instance is destroyed when application exits.

        I do not know if this is relevant but process is started from timer timeout slot when DFU device is detected, I do not wait for a process to finish, I rely on finished signal. My assumption was that the process runs separately from main window thread and thus is should not block anything. It seems that these issues are not existing on Windows, only on MacOS and Linux.

        Although these issues are happening, it seems that the process finishes correctly with exist status QProcess::NormalExit

        Releavant pieces of the code:

        // header
        class DfuProgramming : public QObject
        {
            Q_OBJECT
            // ....
        private:
           QProcess m_dfuProcess;
           QTimer * m_detectDfuTimer;
        }
        
        // source
        DfuProgramming::DfuProgramming(QObject *parent) : QObject(parent)
        {
            // ...
            connect(&m_dfuProcess, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), this, &DfuProgramming::dfuFinishedSlot);
            connect(m_detectDfuTimer, &QTimer::timeout, this, &DfuProgramming::dfuEvent);
            //...
        }
        
        void DfuProgramming::dfuEvent()
        {
            //...
            m_dfuProcess.start(cmd);
        }
        

        What am I doing wrong? Is there any principal issue?

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #3

        @KejPi
        As @Christian-Ehrlicher has said.

        The UI should only block if you call m_dfuProcess.waitForFinished(). Otherwise if your running process is very intensive it might make the system/desktop "sluggish", but not blocked.

        If you allow your calling process to exit before the subprocess has finished then you will get the "process is still running" message. If you intend it to finish then you must make it do so; if you intend it to outlive the calling process then you need to use startDetached().

        1 Reply Last reply
        0
        • Christian EhrlicherC Christian Ehrlicher

          Please use a debugger to see where exactly the program is blocking. I doubt it's during start().
          Also make sure the timer is a single shot timer so the slot is only called once.

          K Offline
          K Offline
          KejPi
          wrote on last edited by
          #4

          It does not block during start(). Actually if I connect to QProcess::readyReadStandardOutput signal, it gets called 3 times before it stops responding. The time when application is unresponsive it actually the time when programmer is erasing and programming attached device. During that time I gen no STDOUT from the process altough there is quite a lot of messages from the process.
          I have reduced the code so only start() is called and no other method of QProcess is used but the result is the same.
          The QProcess is destroyed on application exit thus there is no reason for "process still running" message.

          Ideally I woudl like to continuously capture process stdout using QProcess::readyReadStandardOutput signal thus startDetached() is not suitable.

          JonBJ Christian EhrlicherC 2 Replies Last reply
          0
          • K KejPi

            It does not block during start(). Actually if I connect to QProcess::readyReadStandardOutput signal, it gets called 3 times before it stops responding. The time when application is unresponsive it actually the time when programmer is erasing and programming attached device. During that time I gen no STDOUT from the process altough there is quite a lot of messages from the process.
            I have reduced the code so only start() is called and no other method of QProcess is used but the result is the same.
            The QProcess is destroyed on application exit thus there is no reason for "process still running" message.

            Ideally I woudl like to continuously capture process stdout using QProcess::readyReadStandardOutput signal thus startDetached() is not suitable.

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #5

            @KejPi said in QProcess is blocking UI and destroyed while app running:

            The QProcess is destroyed on application exit thus there is no reason for "process still running" message.
            Ideally I woudl like to continuously capture process stdout using QProcess::readyReadStandardOutput signal thus startDetached() is not suitable.

            You cannot have both of these. If you want to read stdout then as you say you cannot use startDetached(), you must use start(). And in that case you must terminate the subprocess, by whatever means, before you destroy the QProcess, else you will get that warning message. "there is no reason for "process still running" message." --- this is what Qt does, you can't alter it.

            1 Reply Last reply
            0
            • K KejPi

              It does not block during start(). Actually if I connect to QProcess::readyReadStandardOutput signal, it gets called 3 times before it stops responding. The time when application is unresponsive it actually the time when programmer is erasing and programming attached device. During that time I gen no STDOUT from the process altough there is quite a lot of messages from the process.
              I have reduced the code so only start() is called and no other method of QProcess is used but the result is the same.
              The QProcess is destroyed on application exit thus there is no reason for "process still running" message.

              Ideally I woudl like to continuously capture process stdout using QProcess::readyReadStandardOutput signal thus startDetached() is not suitable.

              Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @KejPi said in QProcess is blocking UI and destroyed while app running:

              ctually if I connect to QProcess::readyReadStandardOutput signal, it gets called 3 times before it stops responding

              And where does it get stuck there exactly? Inside the Qt code or do you do a blocking read? Please show the code and the backtrace.

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              K 1 Reply Last reply
              1
              • Christian EhrlicherC Christian Ehrlicher

                @KejPi said in QProcess is blocking UI and destroyed while app running:

                ctually if I connect to QProcess::readyReadStandardOutput signal, it gets called 3 times before it stops responding

                And where does it get stuck there exactly? Inside the Qt code or do you do a blocking read? Please show the code and the backtrace.

                K Offline
                K Offline
                KejPi
                wrote on last edited by KejPi
                #7

                It seems that the problem is somewhere in my app, it is currently not clear where but minimal example I was trying to prepare to share here is working as expected. However full app does not work and I cannot even stop the code to see where it is stuck :-(

                EDIT: rootcause found - another timer was calling the same executable but with waiting for result. This was causing problem as the second process was waiting for the first to complete (this is limitation of the executable I am running).

                1 Reply Last reply
                0
                • K KejPi has marked this topic as solved on

                • Login

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