Important: Please read the Qt Code of Conduct -

Run multiple QEventLoops in parallel (for QtNetwork)

  • I try to extend an old program with a Qt-network support. Having a LAN communication with these libraries needs to run the .exec() of the QEventLoop to really start working (i.e.: accept connections, receive, send, etc.)

    The problem

    I don't know where this event loop is in the main program and because I vaguely know about it's design I prefer a solution that is as indipendent as possible.

    My idea

    I already checked I don't need the main-QEventLoop, and it's alright to make another one just for the networking (i.e. nesting). Unfortunately I can't figure out how to run both loops in parallel, since my program stops at the nested-.exec() and so the main program is on halt too.

    So my main intention is actually to extend the main program with a Qt-Networking, I'm open for other solutions too.

    Thanks for any advise

  • Lifetime Qt Champion

    I don't understand: if your app already have an event loop why do you need a second one?

  • @jsulm since the main event loop doesn't get triggered for some reason

  • Lifetime Qt Champion

    Why it isn't triggered?
    Do you block it somewhere (endless loop)?
    Instead to start a new event loop you should check what is wrong with your code.

  • @jsulm it's not my fault. After having a deeper look into the main application I realize it is not a Qt-program at all, so there will never be a .exec().

    Right now I'm thinking about making a thread for the the .exec()-loop and as it looks for now it is running the main-app and my network extension smoothly. However I'm not a pro when it comes to QEventLoops but could this generate errors or general problems with my suggested solution ? (E.g.: Is my signal/slot procedure for connecting to incomming correspondences guaranteed or may it be (because at that moment the thread was not running), that these request get lost)

  • Lifetime Qt Champion

    I never tried to start a thread with event loop in a program without main event loop (QApplication). My guess: it will work inside your thread, but you will not be able to communicate with the thread from main thread using signals/slots.