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. [Solved]a question about connecting signal and slot

[Solved]a question about connecting signal and slot

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

    In book Foundations of Qt Development,it says "Trying to specify signal or slot argument values when connecting will cause your code to fail at run-time. The connect function understands only the argument types."
    I don't understand.Since connect function understands only signal's and slot's arguments types .Why to specify signal or slot argument values when connecting cause your code to fail at run-time?

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

      In Qt4 (there is a change here in Qt5...) signal connection are parsed by MOC (meta-object compiler), and stored as strings. Connections are made at run-time using those strings. I'm not sure it actually fails, but it certainly might.

      (Z(:^

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

        Yes, it actually fails.

        Many people try to do things like connecting a signal without an argument to a slot with an argument given in the connect statement, but that is impossible. So, this does not work:
        @
        connect(myButton5, SIGNAL(clicked()), this, SLOT(mySlot(5))); // Fail!
        @

        What's more, you cannot even use the argument names in the connect call, only the argument types or the connect will fail. Here at work we use our own connect function, a thin wrapper around connect. It asserts if the connect fails, and it catches these kinds of problems before we release code to customers.

        Note that in Qt 5, there are template-based connect statements that even work with lambda expressions (if you use C++11). That way, you actually can make connect statements like the above one, though they look a bit different of course.

        1 Reply Last reply
        0
        • N Offline
          N Offline
          nimingzhe2008
          wrote on last edited by
          #4

          I understand.Thank you very much.

          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