QProcess signal for when QMainWindow is on screen

  • I have a launcher application which displays icons of a configured list of applications.

    When the user clicks on an icon, a QProcess launches the application.

    For visual feedback, I want to display a wait cursor from the time when the user selects an icon, until the requested app's QMainWindow is on-screen.

    void RocketLauncher::onItemSelect(QListWidgetItem* item)
        QProcess* process = new QProcess();
        QObject::connect(process, &QProcess::started, [&]()
                    QApplication::restoreOverrideCursor(); // this fires well before the child process's main window is displayed

    The problem that I'm having is that the QProcess::started signal fires immediately, but it still takes some time for the child process's QMainWindow to show up on-screen.

    As such, my call to QApplication::restoreOverrideCursor() executes immediately, and there is no visual cue to the user that the application is still being launched.

    Is there some way I can get signalled that the QMainWindow is on screen?

  • Lifetime Qt Champion


    Unless these application somehow signals that they are shown, there's no way for QProcess to know that.

    Note that you have a memory leak here. You never delete the QProcess objects attached to the application you started.

    If it's not something you want to handle, then you can also call startDetached, however there's no communication possible when starting a process like that.

    Hope it helps

  • @SGaist - thanks for your input.

    I found this document from freedesktop.org regarding a Startup notification protocol

    The précis reads:

    This document specifies a mechanism allowing a desktop environment to
    track application startup, to provide user feedback and other

    There is something in the Gnome docs about using "StartupNotify" in launchers.

    Also, in this SO question there is something about "X-KDE-StartupNotify" and its interaction with QApplication.

    I would expect there is something built into QApplication, but I'm not sure what to search for?

  • Lifetime Qt Champion

    You should take a look at the xcb platform plugin.

  • @SGaist said:

    xcb platform

    Wow - that's pretty low-level!

    I've managed to find my way here: http://code.qt.io/cgit/qt/qtbase.git/tree/src/plugins/platforms/xcb

    TBH at this point I'm getting a bit out of my depth.

    Any suggestions on examples of this code being used somewhere? Perhaps in some KDE app or some such?


  • Lifetime Qt Champion

    Basically, it's not a part of Qt that you access directly. It's part of the platform plugins that abstracts away the differences between the various supported OSs.

    The best I can recommend is to contact the KDE folks about how the startup notification is handled by them.

Log in to reply