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. Qt signal and slot internal connection details

Qt signal and slot internal connection details

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 703 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.
  • JKSHJ JKSH

    @Circuits said in What does it mean when an entire function is a slot?:

    how can an entire function be a slot?

    Like @JonB said, a slot is a function that is intended to run when a signal is emitted.

    Could you describe what you think a slot should be?

    Also, it's a private slot, when would you want a slot to be private?

    When you want to implement event-driven logic inside your class, but you don't want the slot function to be called by anyone outside the class.

    @JonB said in What does it mean when an entire function is a slot?:

    I believe one of the changes in Qt 5 for the new signal/slots syntax was that slots now have to be public, but I could be wrong :)

    Signals are now be public; slots are unchanged.

    Qt 4: #define signals protected
    Qt 5: #define signals public

    See

    • https://code.woboq.org/qt5/qtbase/src/corelib/kernel/qobjectdefs.h.html#_M/Q_SIGNALS
    • https://www.kdab.com/wp-content/uploads/stories/slides/DD13/dd13_signalsslots.pdf

    [EDIT: Discussion about public/protected/private forked to https://forum.qt.io/topic/107926/qt-signal-and-slot-internal-connection-details --JKSH]

    JonBJ Offline
    JonBJ Offline
    JonB
    wrote on last edited by JKSH
    #1

    [EDIT: Forked from https://forum.qt.io/topic/107901/what-does-it-mean-when-an-entire-function-is-a-slot --JKSH]

    @JKSH said in What does it mean when an entire function is a slot?:

    Signals are now be public; slots are unchanged.

    Yep, thanks, I had a funny feeling I was getting that the wrong way round :)

    I believe from reading the discussion about why the change (to do with the new signal/slot syntax, I believe), they never wanted to make #define signals public, but had to for compilation, so it's presumably good to regard/pretend as though it were still #define signals protected, i.e. never invoke signal from outside world.

    Chris KawaC 1 Reply Last reply
    0
    • JonBJ JonB

      [EDIT: Forked from https://forum.qt.io/topic/107901/what-does-it-mean-when-an-entire-function-is-a-slot --JKSH]

      @JKSH said in What does it mean when an entire function is a slot?:

      Signals are now be public; slots are unchanged.

      Yep, thanks, I had a funny feeling I was getting that the wrong way round :)

      I believe from reading the discussion about why the change (to do with the new signal/slot syntax, I believe), they never wanted to make #define signals public, but had to for compilation, so it's presumably good to regard/pretend as though it were still #define signals protected, i.e. never invoke signal from outside world.

      Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @JonB said in What does it mean when an entire function is a slot?:

      so it's presumably good to regard/pretend

      All you can do is pretend as it doesn't really matter if a signal is public, protected or private. The meta-system circumvents these language boundaries and you can always call even a private signal of another class via invokeMethod().

      JonBJ 1 Reply Last reply
      0
      • Chris KawaC Chris Kawa

        @JonB said in What does it mean when an entire function is a slot?:

        so it's presumably good to regard/pretend

        All you can do is pretend as it doesn't really matter if a signal is public, protected or private. The meta-system circumvents these language boundaries and you can always call even a private signal of another class via invokeMethod().

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #3

        @Chris-Kawa
        Yes, but the change was for the new connection syntax, not the "magic" of the old SIGNAL/SLOT() mechanism.

        I'm not a C++-er (I'm stinky Python/PyQt, where just about everything is public and everything can access everything else, lovely!), but I do like to understand how it's supposed to be from C++. So please correct me if I'm wrong, but:

        • In the new syntax, both signals & slots macros resolve to public.
        • This is required to allow the new, direct connect(signal, slot) from the outside world, code not in either the signal or slot classes.
        • To raise a signal you use emit(), and the emit part resolves to nothing, so it's just a straight call to the signal function.
        • In the old days you could keep signals as protected, so that only the signalling/emitting class could emit() the signal.
        • Now that signals has to be public, anybody could call the emit(), but Qt didn't really want that. So you are "politely requested" not to actually write an emit() unless you are inside the signal class, as that's how it is intended to be used.

        Please correct me if I have misunderstood.

        Chris KawaC 1 Reply Last reply
        0
        • JonBJ JonB

          @Chris-Kawa
          Yes, but the change was for the new connection syntax, not the "magic" of the old SIGNAL/SLOT() mechanism.

          I'm not a C++-er (I'm stinky Python/PyQt, where just about everything is public and everything can access everything else, lovely!), but I do like to understand how it's supposed to be from C++. So please correct me if I'm wrong, but:

          • In the new syntax, both signals & slots macros resolve to public.
          • This is required to allow the new, direct connect(signal, slot) from the outside world, code not in either the signal or slot classes.
          • To raise a signal you use emit(), and the emit part resolves to nothing, so it's just a straight call to the signal function.
          • In the old days you could keep signals as protected, so that only the signalling/emitting class could emit() the signal.
          • Now that signals has to be public, anybody could call the emit(), but Qt didn't really want that. So you are "politely requested" not to actually write an emit() unless you are inside the signal class, as that's how it is intended to be used.

          Please correct me if I have misunderstood.

          Chris KawaC Offline
          Chris KawaC Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by
          #4

          I'm stinky Python/PyQt, where just about everything is public and everything can access everything else, lovely!

          Savages... :P

          Please correct me if I have misunderstood.

          Sounds right except for the part where previously only the owning class could call protected signal - as I said earlier, you could still call it (indirectly) via invokeMethod(). Anyway it's history and everything is public now, like in Python... <shivers>...

          JonBJ 1 Reply Last reply
          0
          • Chris KawaC Chris Kawa

            I'm stinky Python/PyQt, where just about everything is public and everything can access everything else, lovely!

            Savages... :P

            Please correct me if I have misunderstood.

            Sounds right except for the part where previously only the owning class could call protected signal - as I said earlier, you could still call it (indirectly) via invokeMethod(). Anyway it's history and everything is public now, like in Python... <shivers>...

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #5

            @Chris-Kawa
            Yes, but invokeMethod() is on QMetaObject, and that's what I refer to as the "magic" of the old ... (look up a string in a table of functions, rather than using language constructs). You have to pass a test before being allowed to use that, and your programming license will be revoked if you don't know what you are doing and get it wrong... :)

            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