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. Event loop
Forum Updated to NodeBB v4.3 + New Features

Event loop

Scheduled Pinned Locked Moved General and Desktop
7 Posts 4 Posters 5.5k Views 3 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.
  • R Offline
    R Offline
    ritesh
    wrote on last edited by
    #1

    Hello all
    I am a new user to qt.
    I wanted to know about qt event loop.
    When is a new event loop started?
    Which event queue does this use . I mean does each event loop has its own event queue or all share one?

    How to check which event loop executed an event . Like is there some mechanism which can be used to assign an id to event loop and hence print it in the event loop to check which event loop is executing this event?

    Regards
    Ritesh

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

      Hi and welcome to devnet,

      The application event loop is started when you call:

      QApplication app(argc, argv);
      QWidget w;
      w.show();
      return app.exec(); << here it starts
      

      You can have secondary event loops tarted when e.g. you call a QDialog's exec function. The events are processed by the current event loop.

      If you want more details about the internals, you should directly read Qt's sources.

      Hope it helps

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • A Offline
        A Offline
        ambershark
        wrote on last edited by
        #3

        QThread's also have their own event loop. And you can create your own event loops with QEventLoop at any time and handle all events with a call to QEventLoop::exec(). Not a whole lot of reasons to do this but the functionality is there if you need it.

        You wouldn't have anything to gain from assigning an ID to an eventloop to see which one was processing the event since you already know based on what loop is running (exception being a QThread loop but you should know which ones it is processing as well based on what signals/slots you connected to the thread).

        Event loops are blocking calls (usually on exec()) so any event that happens will be processed by the currently "blocking" event loop. So if you are running an application event loop app.exec() then it will get all the events. If you start up a modal dialog at some point QDialog::exec() then it will now be getting all the events until it exits.

        The only time this gets a bit confusing is when you are dealing with threads. That is a whole different topic though. I won't go into it here unless you really need me to.

        My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

        1 Reply Last reply
        0
        • R Offline
          R Offline
          ritesh
          wrote on last edited by
          #4

          This is a good information.
          Can you share a code snippet of how could qeventloop can be overwritten.

          Also i understood that there is only 1 event queue which has events posted on it , the event loop which will take up the event will be the one which is currently in picture. I this right statement ? Like if i have an event posted at time X then exec a dialog box ,
          So will the event loop exexed by dialog will process the paintevent posted at time X OR it will only process events coming after it is execed?

          1 Reply Last reply
          0
          • A Offline
            A Offline
            ambershark
            wrote on last edited by
            #5

            You can get more information on overriding event loops from the Qt docs on QEventLoop. I've never needed to do that so I don't have a snippet for you. Not really sure why you would want to have a custom event loop, but it is possible using QEventLoop.

            Typically events posted before an event loop is started are not handled by the new event loop. Although I'm guessing there. I don't know that for sure. If you really want to dig into event loops, you should check out Qt's code itself. In my 15 years of Qt I've never needed to make a custom event loop. It's all handled by the modal object, the application, or the thread.

            My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

            1 Reply Last reply
            0
            • Y Offline
              Y Offline
              yoavmil
              wrote on last edited by
              #6

              if you want to know what object called the event, who emitted the signal, you might want to use sender(), but please tell give more info about you issue.

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @yoavmil beware, signals/slots and events are not the same beast. Emitting a signal doesn't mean there will be an event. i.e. if both objects leaves in the same thread it won't or if the connection type is forced to direct connection.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                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