Help me with "connect" syntax, again.
-
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…)
-
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…)
@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)));
-
@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)));
@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....
-
@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....
@AnneRanch
For the new parameter change the signal and slot tovoid 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 theSIGNAL
&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. OnlySIGNAL()
&SLOT()
are macros. -
@AnneRanch
For the new parameter change the signal and slot tovoid 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 theSIGNAL
&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. OnlySIGNAL()
&SLOT()
are macros.@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, -
@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,@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...
-
@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,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.