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. Help me with "connect" syntax, again.
Forum Updated to NodeBB v4.3 + New Features

Help me with "connect" syntax, again.

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 4 Posters 454 Views 2 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.
  • A Offline
    A Offline
    Anonymous_Banned275
    wrote on last edited by
    #1

    Please help OF to find the syntax error.
    All I am trying to do is to test “emit” in
    an object by passing a QStriung..

    
     
    
    
    EMIT 
    
    emit SIGNAL_Address(localDevice.address().toString());
    
    
    DECARE SIGNAL and SLOT 
    
     signals:
         void SIGNAL_Address(QString string);
    
    private slots:
         void UpateAddress(QString string );
    
    
    DEFINE connect 
            // try connect temporary local
            connect (this,SIGNAL(SIGNAL_Address(&localDevice.address().toString())),
                     this,SLOT(UpateAddress(&localDevice.address().toString())));
    
    
    
    
    
    sippet of app OUTPUT WITH ERROR 
    
    
    "TRACE DEBUG SETTING LOCAL ADAPTERS Form_SetupLocalAdapter::Form_SetupLocalAdapter(QWidget *)@line 17"
    QObject::connect: No such signal Form_SetupLocalAdapter::SIGNAL_Address(&localDevice.address().toString()) in form_setuplocaladapter.cpp:26
    QObject::connect:  (sender name:   'Form_SetupLocalAdapter')
    QObject::connect:  (receiver name: 'Form_SetupLocalAdapter')
    " device info from array 00:15:83:15:A2:CB"
    
    
    
    ps 
    Pretty Please  NOT COMMENTS  ON USING THE OLD STYLE OF CONNECT 
    I  need to walk before I can  run  ( baby steps, baby steps…) 
    
    
    
    
    
    Chris KawaC 1 Reply Last reply
    0
    • A Anonymous_Banned275

      Please help OF to find the syntax error.
      All I am trying to do is to test “emit” in
      an object by passing a QStriung..

      
       
      
      
      EMIT 
      
      emit SIGNAL_Address(localDevice.address().toString());
      
      
      DECARE SIGNAL and SLOT 
      
       signals:
           void SIGNAL_Address(QString string);
      
      private slots:
           void UpateAddress(QString string );
      
      
      DEFINE connect 
              // try connect temporary local
              connect (this,SIGNAL(SIGNAL_Address(&localDevice.address().toString())),
                       this,SLOT(UpateAddress(&localDevice.address().toString())));
      
      
      
      
      
      sippet of app OUTPUT WITH ERROR 
      
      
      "TRACE DEBUG SETTING LOCAL ADAPTERS Form_SetupLocalAdapter::Form_SetupLocalAdapter(QWidget *)@line 17"
      QObject::connect: No such signal Form_SetupLocalAdapter::SIGNAL_Address(&localDevice.address().toString()) in form_setuplocaladapter.cpp:26
      QObject::connect:  (sender name:   'Form_SetupLocalAdapter')
      QObject::connect:  (receiver name: 'Form_SetupLocalAdapter')
      " device info from array 00:15:83:15:A2:CB"
      
      
      
      ps 
      Pretty Please  NOT COMMENTS  ON USING THE OLD STYLE OF CONNECT 
      I  need to walk before I can  run  ( baby steps, baby steps…) 
      
      
      
      
      
      Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @AnneRanch Same as always. Macros in connect don't take variables. They take function signatures, so

      connect (this, SIGNAL(SIGNAL_Address(QString)),                 
               this, SLOT(UpateAddress(QString)));
      
      A 1 Reply Last reply
      1
      • Chris KawaC Chris Kawa

        @AnneRanch Same as always. Macros in connect don't take variables. They take function signatures, so

        connect (this, SIGNAL(SIGNAL_Address(QString)),                 
                 this, SLOT(UpateAddress(QString)));
        
        A Offline
        A Offline
        Anonymous_Banned275
        wrote on last edited by
        #3

        @Chris-Kawa Thank you. I want to modify my SIGNAL from this

        emit SIGNAL_Address(localDevice.address().toString());

        to this , adding an index

        emit SIGNAL_Address(localDevice.address().toString(), index );

        that way I can have only one SLOT function for multiple QString values.

        Could you recommend a doc/ link for me to actually learn about how the "connect" macro is coded. I am little tired of just blindly copying and QT examples do not help.

        Knowing how the macro is formed may help me to start using the new format....

        JonBJ 1 Reply Last reply
        0
        • A Anonymous_Banned275

          @Chris-Kawa Thank you. I want to modify my SIGNAL from this

          emit SIGNAL_Address(localDevice.address().toString());

          to this , adding an index

          emit SIGNAL_Address(localDevice.address().toString(), index );

          that way I can have only one SLOT function for multiple QString values.

          Could you recommend a doc/ link for me to actually learn about how the "connect" macro is coded. I am little tired of just blindly copying and QT examples do not help.

          Knowing how the macro is formed may help me to start using the new format....

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

          @AnneRanch
          For the new parameter change the signal and slot to

          void SIGNAL_Address(QString string, int index);
          void UpateAddress(QString string, int index);
          

          and the connect:

          connect(this, &Form_SetupLocalAdapter::SIGNAL_Address,
                  this, &Form_SetupLocalAdapter::UpateAddress);
          

          You can add/remove/change parameters to both the signal and slot, so long as they correspond, and you never have to alter the connect() statement.

          If you want to do it with old-style connect() change the SIGNAL & SLOT() parameters each time to match:

          connect (this, SIGNAL(SIGNAL_Address(QString, int)),                 
                   this, SLOT(UpateAddress(QString, int)));
          

          BTW

          Knowing how the macro is formed may help me to start using the new format....

          connect() is not a macro. Only SIGNAL() & SLOT() are macros.

          A 1 Reply Last reply
          0
          • JonBJ JonB

            @AnneRanch
            For the new parameter change the signal and slot to

            void SIGNAL_Address(QString string, int index);
            void UpateAddress(QString string, int index);
            

            and the connect:

            connect(this, &Form_SetupLocalAdapter::SIGNAL_Address,
                    this, &Form_SetupLocalAdapter::UpateAddress);
            

            You can add/remove/change parameters to both the signal and slot, so long as they correspond, and you never have to alter the connect() statement.

            If you want to do it with old-style connect() change the SIGNAL & SLOT() parameters each time to match:

            connect (this, SIGNAL(SIGNAL_Address(QString, int)),                 
                     this, SLOT(UpateAddress(QString, int)));
            

            BTW

            Knowing how the macro is formed may help me to start using the new format....

            connect() is not a macro. Only SIGNAL() & SLOT() are macros.

            A Offline
            A Offline
            Anonymous_Banned275
            wrote on last edited by
            #5

            @JonB Thanks, I already have that implemented and it works as expected.

            I still have an opinion that QT docs are not the best to understand how "connect" works. I just spent a time to find out, the obvious, that "connect" needs to be in code before "emit". Duh.
            So the "connect" AKA callback FUNCTION uses SIGNAL / SLOT declared as functions as a macro parameter. ..
            A real mess to actually understand how the whole scheme works in QT,

            Christian EhrlicherC Chris KawaC 2 Replies Last reply
            0
            • A Anonymous_Banned275

              @JonB Thanks, I already have that implemented and it works as expected.

              I still have an opinion that QT docs are not the best to understand how "connect" works. I just spent a time to find out, the obvious, that "connect" needs to be in code before "emit". Duh.
              So the "connect" AKA callback FUNCTION uses SIGNAL / SLOT declared as functions as a macro parameter. ..
              A real mess to actually understand how the whole scheme works in QT,

              Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @AnneRanch said in Help me with "connect" syntax, again.:

              I just spent a time to find out, the obvious, that "connect" needs to be in code before "emit".

              I mean - how should it work otherwise...

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              1 Reply Last reply
              1
              • A Anonymous_Banned275

                @JonB Thanks, I already have that implemented and it works as expected.

                I still have an opinion that QT docs are not the best to understand how "connect" works. I just spent a time to find out, the obvious, that "connect" needs to be in code before "emit". Duh.
                So the "connect" AKA callback FUNCTION uses SIGNAL / SLOT declared as functions as a macro parameter. ..
                A real mess to actually understand how the whole scheme works in QT,

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

                C'mon. It's one function with 4 parameters. It doesn't need a book. It's what you learn on the first Qt lesson. We've been over this countless times for almost 4 years now. Maybe create an empty project and just add a button and practice just connects? It really shouldn't be that hard for you after all that time. I really don't want to sound like an a-hole, but it's really getting annoying to see dozen of people have to repeat the same things over and over and over and over and over and... you get the point.

                @AnneRanch said:

                I just spent a time to find out, the obvious, that "connect" needs to be in code before "emit"

                Well... that's... I don't want to use word "obvious", but if you don't connect anything how is Qt supposed to know what you want to be called when you emit? It's like declaring a variable before you can use it. Yes, the thing needs to exist first before it can be used. Same with connection. It has to exist to be triggered. Function has to be declared before it is called. Class has to be declared before it is instantiated. Pretty much everything in C++ works this way.

                So the "connect" AKA callback FUNCTION

                It's not a callback function. It's a function that registers a callback (slot) with a signal. When an object emits a signal a slot of another object is called. That's all there is to it. It's very basic. The documentation is more than exhaustive. If you want the low level detail (you don't need them to use it) there's this article.

                uses SIGNAL / SLOT declared as functions as a macro parameter

                No. SIGNAL and SLOT are macros that turn whatever you pass them into strings, e.g. if you type SLOT(foo()) it will turn it into string "foo()". These strings are used as keys to look up function pointers. That's one of the reasons we've been trying to convince you for years to start using the pointer syntax. It's easier to understand, faster, safer... ah, I won't repeat myself. You know it already. We've repeated it countless times.

                1 Reply Last reply
                2

                • Login

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