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. A question about connect funtion
QtWS25 Last Chance

A question about connect funtion

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 263 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.
  • S Offline
    S Offline
    Saymyname
    wrote on last edited by
    #1

    Assuming that there is signal fooSig(const QString& str), and if I wrote the connect funtion like connect(this, SIGNAL(fooSig(QString))...), it will work well. This is confused, shouldn't it be the prototype of the signal function(of course without return type) in the parethesis of SIGNAL?

    JonBJ 1 Reply Last reply
    0
    • S Saymyname

      Assuming that there is signal fooSig(const QString& str), and if I wrote the connect funtion like connect(this, SIGNAL(fooSig(QString))...), it will work well. This is confused, shouldn't it be the prototype of the signal function(of course without return type) in the parethesis of SIGNAL?

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

      @Saymyname
      Don't use the SIGNAL/SLOT() old-style connect() syntax which was superseded over a decade ago. Use the New Signal Slot Syntax which is preferable for a number of reasons, including avoiding your issue and making it much clearer.

      S 1 Reply Last reply
      0
      • S Offline
        S Offline
        Saymyname
        wrote on last edited by
        #3

        @johnsmith3321 Thank you for you answer, that's pretty comprehensive about how to use those two macros

        1 Reply Last reply
        0
        • JonBJ JonB

          @Saymyname
          Don't use the SIGNAL/SLOT() old-style connect() syntax which was superseded over a decade ago. Use the New Signal Slot Syntax which is preferable for a number of reasons, including avoiding your issue and making it much clearer.

          S Offline
          S Offline
          Saymyname
          wrote on last edited by
          #4

          @JonB OK, the page is very helpful, thank you.

          JonBJ 1 Reply Last reply
          0
          • S Saymyname

            @JonB OK, the page is very helpful, thank you.

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

            @Saymyname
            So your case would become:

            connect(this, &MyClass::fooSig, this, &MyClass::fooSlot);
            

            Don't you think this is nicer? It is also checked at compile time, so you will get a compilation error if the signal or slot does not exist or does not take the right arguments.

            1 Reply Last reply
            3

            • Login

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