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. Cleaning up after QApplication
Qt 6.11 is out! See what's new in the release blog

Cleaning up after QApplication

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 301 Views 2 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.
  • G Offline
    G Offline
    Gints
    wrote on last edited by
    #1

    I'm porting a Qt desktop application to Linux (Ubuntu 19.10, 64bit desktop, Qt 5.12.5, gcc version 9.2.1), and am seeing some unexpected threads remaining alive after QApplication is finished.

    Here's the minimum repro:

    #include <QApplication>
    #include <unistd.h>
    int main(int argc, char * argv[]) {
        {
            QApplication app(argc, argv);
            sleep(1);
        }
        sleep(10);
        return 0;
    }
    

    If I debug the application at various points in time, here's what I see:

    • Before the constructor of QApplication is run, just one thread, the main thread, exists, as expected.
    • After the constructor of QApplication is run, 4 additional threads get created:
      • QXcbEventQueue
      • gmain
      • gdbus
      • QDBusConnection
    • After the destructor of QApplication is run, the QXcbEventQueue thread goes away.
    • Even after the second sleep of 10 seconds is done, the 3 other threads, besides the main thead, remain alive:
      • gmain
      • gdbus
      • QDBusConnection

    I'm looking for a way to properly end these threads (and do other clean up that I might not be aware of at the moment) after QApplication has finished (of course, in the real app I call app.exec() and do other things) and has been destroyed.

    This is not an issue in the application itself, which does not seem to have a problem with reaching the end of main with those 3 threads still alive.

    The application is part of a larger suite of libraries / other applications that are thoroughly tested using Google Test, and the tests include some Death Tests, which, if executed after having run some tests that involve running a QApplication, complain about forking an application that has multiple threads, and get stuck and never finish, presumably, for this reason.

    Any hints on how I might be able to get rid of those threads & perform a full cleanup of other stuff (if any) after QApplication?

    1 Reply Last reply
    0

    • Login

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