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. Events vs signal-slot system
QtWS25 Last Chance

Events vs signal-slot system

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 4 Posters 3.6k 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.
  • B Offline
    B Offline
    brkonator
    wrote on last edited by brkonator
    #1

    Hello, I was wondering, why some Qt "events" can only be processed using the event system (e.g. QMouseEvent) and some using the signal-slot system (e.g. QPushButton::clicked - I know, this could also be simulated using mouse press and release events but still - it's a separate signal instead of an event). Is this mostly because of performance reasons? Is there some other reason? Thanks in advance.

    1 Reply Last reply
    1
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      I think the reason why events are used where they are is because of 2 things:

      • events are closely related to and integrated with Operating System events - it's simply easier to implement and to think about system events using QEvent than it would be with signals and slots
      • events are pretty much globally available and more low-level

      Is this mostly because of performance reasons?

      I don't know, but I doubt it.

      (Z(:^

      1 Reply Last reply
      4
      • Kent-DorfmanK Offline
        Kent-DorfmanK Offline
        Kent-Dorfman
        wrote on last edited by
        #3

        yeah. they are apples an oranges. there is a well defined deliniation between signals and events but it's hard to explain. events are generally triggered by hardware or OS "events" or things that may be based on an interrupt of some sort. signals are purely application level triggers to fire some method based on engineered behavior. there is some overlap, such as timer timeouts but in general think of the events as functions that are triggered by quazi-interrupts or OS level triggers.

        1 Reply Last reply
        4
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          An interesting point here is, I think, that in theory Qt could be rewritten to use only signals and slots. There would have to be some global (yikes!) QMouse object which would be sending mouse signals, global keyboard object which would send key signals etc.

          (Z(:^

          Kent-DorfmanK kshegunovK 2 Replies Last reply
          2
          • sierdzioS sierdzio

            An interesting point here is, I think, that in theory Qt could be rewritten to use only signals and slots. There would have to be some global (yikes!) QMouse object which would be sending mouse signals, global keyboard object which would send key signals etc.

            Kent-DorfmanK Offline
            Kent-DorfmanK Offline
            Kent-Dorfman
            wrote on last edited by
            #5

            @sierdzio Sure. I can think of other similar frameworks using that approach, but they are nowhere near as sophisticated of mature as Qt.

            1 Reply Last reply
            1
            • B Offline
              B Offline
              brkonator
              wrote on last edited by
              #6

              Thanks for your replies, it's much clearer to me now.

              1 Reply Last reply
              0
              • sierdzioS sierdzio

                An interesting point here is, I think, that in theory Qt could be rewritten to use only signals and slots. There would have to be some global (yikes!) QMouse object which would be sending mouse signals, global keyboard object which would send key signals etc.

                kshegunovK Offline
                kshegunovK Offline
                kshegunov
                Moderators
                wrote on last edited by kshegunov
                #7

                @sierdzio said in Events vs signal-slot system:

                An interesting point here is, I think, that in theory Qt could be rewritten to use only signals and slots.

                Probably not, but even if you're right it's going to be one grimy mess. One "big thing" about events is that you can propagate them through the object tree, which I've used in a project last year. My use case was more or less a composition of entry and exit points for a network comm interface, where you could (and have) multiple sources and sinks, and attach at different points of the "pipeline". In that case I was both sinking and bubbling up the events through the object tree aplenty, that's not that straightforward to design with signal/slots only (which I used as my "extraction points").

                @brkonator
                Events are lower level, they usually refer to the object itself and you're rarely going to see QCoreApplication::sendEvent or QCoreApplication::postEvent used explicitly, although it does happen. Signal-slot connections are more like callbacks, much more mature and nice (obviously). As a matter of fact some signal-slot connections are executed through an event, specifically the queued connections' executions are packed in a QEvent::MetaCall event internally.

                Read and abide by the Qt Code of Conduct

                1 Reply Last reply
                7

                • Login

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