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. General question about Signals/Slots compared to lamda functor passing
QtWS25 Last Chance

General question about Signals/Slots compared to lamda functor passing

Scheduled Pinned Locked Moved General and Desktop
signals & slotssignalsslotslamdafunctors
5 Posts 3 Posters 1.9k 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.
  • P Offline
    P Offline
    panch
    wrote on 25 Sept 2015, 09:28 last edited by
    #1

    Hi all,

    I have completed my first Qt application. I have previously been used to pass functors to other classes to create a form of callback functionality, which has worked pretty well.
    With Qt I'm of course using the Signals and slots, and since I'm used to lambas I felt it was a welcome addition as of 5.5 to add those to the slots functionality.

    However, I am confused as to what I gain compared to just using lamdas as callback function?

    I know that signals/slots are safe aross threads, so thats one advantage compared to functors.

    As the documentation states, classes that don't know anything about each other can connect to eachothers signals/slots but is that true? You still need both objects to create the connection, right?

    So please enlighten me, I'm baffled :)

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 25 Sept 2015, 22:45 last edited by
      #2

      Hi,

      Yes you need both objects but they really don't need to know each other. e.g. QSerialPort doesn't need to know that you connected it to another class that will drive an LCD and that class also don't need to know that it's a QSerialPort that is feeding it data, one is a producer and the other a consumer and can be replaced easily if needed.

      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
      • P Offline
        P Offline
        panch
        wrote on 28 Sept 2015, 11:23 last edited by
        #3

        Ok, I see that the main advantage is that you can emit a signal to multiple recipients, which the functor is not able to, since it's a 1:1 relationship.

        Would you then restrict the signals/slots to only GUI-related information passing? As a proper way of developing Qt applications, I mean...

        J 1 Reply Last reply 29 Sept 2015, 12:06
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 28 Sept 2015, 21:55 last edited by
          #4

          No, certainly not. There are no such limitation.

          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
          • P panch
            28 Sept 2015, 11:23

            Ok, I see that the main advantage is that you can emit a signal to multiple recipients, which the functor is not able to, since it's a 1:1 relationship.

            Would you then restrict the signals/slots to only GUI-related information passing? As a proper way of developing Qt applications, I mean...

            J Offline
            J Offline
            JKSH
            Moderators
            wrote on 29 Sept 2015, 12:06 last edited by
            #5

            @panch said:

            Would you then restrict the signals/slots to only GUI-related information passing? As a proper way of developing Qt applications, I mean...

            QNetworkAccessManager emits signals to tell the world that a download has completed. QSerialPort emits signals to tell the world that some data has been received. QMediaPlayer emits signals to tell the world that its playback status has changed.

            These show that signals and slots are "proper" for developing all kinds of things, not just GUIs.

            Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

            1 Reply Last reply
            0

            1/5

            25 Sept 2015, 09:28

            • Login

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