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. Run multiple QEventLoops in parallel (for QtNetwork)

Run multiple QEventLoops in parallel (for QtNetwork)

Scheduled Pinned Locked Moved Solved General and Desktop
qtnetworkqeventloopparallel
6 Posts 2 Posters 3.2k Views
  • 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.
  • Q Offline
    Q Offline
    QtExchange
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

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

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      Q 1 Reply Last reply
      0
      • jsulmJ jsulm

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

        Q Offline
        Q Offline
        QtExchange
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by jsulm
          #4

          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.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          Q 1 Reply Last reply
          1
          • jsulmJ jsulm

            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.

            Q Offline
            Q Offline
            QtExchange
            wrote on last edited by QtExchange
            #5

            @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)

            1 Reply Last reply
            0
            • jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              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.

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              1

              • Login

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