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. SIGNAL and SLOT: are them 1 or 2?
Forum Updated to NodeBB v4.3 + New Features

SIGNAL and SLOT: are them 1 or 2?

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

    Hello. http://qt-project.org/doc/qt-5.0/qtcore/qmetamethod.html#MethodType-enum states that QMetaMethod::Signal is defined to 1, while QMetaMethod::Slot is 2. The same time, if we look into qobjectdefs.h, it says:
    @# define SLOT(a) qFlagLocation("1"#a QLOCATION)

    define SIGNAL(a) qFlagLocation("2"#a QLOCATION)@

    That is, macro SLOT () adds 1 to method's signature, whereas macro SIGNAL () adds 2.
    Is this intended, or did it happened randomly, or just for fun to further complicate matters, or what?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mcosta
      wrote on last edited by
      #2

      Hi,

      this macro defines Method Location that is
      @
      private --> 0
      protected --1
      public --> 2
      @

      then your code define SLOT as protected and SIGNAL as PUBLIC

      Once your problem is solved don't forget to:

      • Mark the thread as SOLVED using the Topic Tool menu
      • Vote up the answer(s) that helped you to solve the issue

      You can embed images using (http://imgur.com/) or (http://postimage.org/)

      1 Reply Last reply
      0
      • B Offline
        B Offline
        bipll
        wrote on last edited by
        #3

        [quote author="mcosta" date="1363872399"]Hi,

        this macro defines Method Location that is
        @
        private --> 0
        protected --1
        public --> 2
        @

        then your code define SLOT as protected and SIGNAL as PUBLIC[/quote]
        What exactly macro do you mean? I've quoted definitions of SLOT and SIGNAL from the header, no notion of private or protected there (which, by the way, would require calling some QObject or QMetaObject methods). If I write
        @ qDebug() << SLOT(abcde);
        qDebug() << SIGNAL(defgh);@

        I get exactly
        @1abcde
        2defgh
        @

        in the output. These macros do nothing but substitute '1' or '2' at the head of the string, and add FILE:LINE (something like "main.cpp:15") past the ending zero char, nothing more.

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

          Hi,

          These macros are used by moc to make the Qt magic work. You can dig in the moc generated files and moc's sources to find out more about how they work.

          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
          • B Offline
            B Offline
            bipll
            wrote on last edited by
            #5

            Isn't moc working with headers only? Macro expanding is done in cpp-sources and thus should be totally mocless.

            1 Reply Last reply
            0
            • C Offline
              C Offline
              ChrisW67
              wrote on last edited by
              #6

              moc reads the supplied header files and generates implementation code containing lookup tables for signals and slots using names prefixed with 0, 1 or 2 for internal purposes.

              The macros do the matching manipulation for the C++ compiler and programmer's benefit so that the connect() function ultimately uses similarly mangled names.

              1 Reply Last reply
              0
              • B Offline
                B Offline
                bipll
                wrote on last edited by
                #7

                Hell yeah, that's pretty obvious, why are you writing it anyway? My question was: how come QMetaMethod::Signal equals to 1, while the SIGNAL () macro prefixes names with "2", and in reverse for slots.
                Wouldn't it be more convenient, if the two digits were the same?
                Even more, if SIGNAl () and SLOT () were explicitely standardized? Currently if you have the only the signature of a signal in a string, you have to use something like "QObject::connect(sender, sender->metaObject ()->method(sender->metaObject ()->indexOfMethod(signal))..." thus using QMetaMethod-aware overload of QObject::connect. Maybe, just adding "2" to it would be more convenient, as of programmer's side, but currently it's illegal, because the definition of SIGNAL is obscured.
                Same for slots.
                (Of course, these talks were of any sence earlier. Qt5.0 supports connecting signals to arbitrary functors, so we're just moving to pure lambdas. All aboard!
                Yet even lambdas have to be built from strings.)

                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