Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-97049

QProcess freezes during user interaction with Qt Quick application window

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.15.2
    • None
    • Windows 10 20H2 x64, MSVC 142 2019

    Description

      In a Qt Quick application, a QProcess (running a CLI program) started in a C++ class object, "freezes" (or at least the slot connected to its finished signal never executes) during user interaction with Qt Quick application window.

      The C++ code of the class:

      Backend::Backend(QObject *parent) : QObject(parent)
      {
          _someCounter = 0;
      
          _whoAmI.setProgram("whoami");
          connect(
              &_whoAmI, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
              [=](int exitCode, QProcess::ExitStatus exitStatus) { doneSomething(exitCode, exitStatus); }
          );
      
          connect(&_timer, &QTimer::timeout, this, &Backend::doSomething);
          _timer.setSingleShot(false);
          _timer.start(800);
      }
      
      void Backend::doSomething()
      {
          if (_whoAmI.state() == 0) { _whoAmI.start(); }
          else { qDebug() << "waiting till previously started process ends..."; }
      }
      
      void Backend::doneSomething(int exitCode, QProcess::ExitStatus exitStatus)
      {
          qDebug() << "Exit code:" << exitCode << " | status:" << exitStatus;
      
          _someCounter++;
      
          QString rez = _whoAmI.readAllStandardOutput().trimmed();
      
          emit gotResults(
              QString("%1 - %2 - %3").arg(
                  QDateTime::currentDateTime().toString(),
                  QString::number(_someCounter),
                  rez
              )
          );
      }
      

      This class is then registered in main.cpp:

      qmlRegisterType<Backend>("io.qt.Backend", 1, 0, "Backend");
      

      and used in main.qml:

      Backend {
          id: backend
      
          onGotResults: {
              applicationLog.append(msg);
          }
      }
      

      The full project source code is attached in qml-cpp-blocking.zip

      Here's a video of the problem occurring: blocking.mp4

      So in case of either of these interactions:

      1. Moving the application window
      2. Resizing the application window
      3. Navigating the application menu

      the QProcess running in Backend object never finishes (or its finished signal never triggers the connected slot?).

      I've encountered this problem with Qt 5.15.2 on Windows. The same application works fine on Linux and Mac OS, I couldn't reproduce this problem there.

      Also I couldn't reproduce it with Qt 6.2.0 on Windows, which is good news.

      Attachments

        1. blocking.mp4
          3.10 MB
        2. qml-cpp-blocking.zip
          4 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            artemsyd Artem Sidyakin
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes