Unsolved Signal and Slot connected by slot not called?
-
@KroMignon said in Signal and Slot connected by slot not called?:
emit is a semantical sugar, it has no signification, it is only for the reader to identify usage of a signal
emit pobjModule->sendJSON(objJSON); is absolutely the same as pobjModule->sendJSON(objJSON);
You are simply call a member, nothing more, nothing less.Allow me to interpret this reoccurring "sugary " statement
emit pobjModule->sendJSON(objJSON);
using "emit" is therefore equivalent to
int a = 10; /// set variable a to 10
where
/// set variable a to 10 is a superficial sugar telling nothing about what "a" is /does
IMHO
repeating the "emit does nothing , it is a sugar " directly discourages to write readable code , unless the coder objective is to write obfuscated stuff for false "job security".
Cheers
' -
@AnneRanch said in Signal and Slot connected by slot not called?:
repeating the "emit does nothing , it is a sugar " directly discourages to write readable code , unless the coder objective is to write obfuscated stuff for false "job security".
Cheers
'You are misunderstanding my comments.
All I want to say with "semantical sugar", is that there is nothing which is magically done here.
If emitting signal is working somewhere, it will work everywhere.And if the slot is not called by one specific call only, it simply means that the thread event loop is not working/locked.
I am not an English native speaker, so I try to explain the best I can.
-
@KroMignon , thank you, np.
-
- Write a
qDebug()
message just after theQObject::connect(this, &clsModule::sendJSON, this, &clsModule::onSendJSON);
. - Write a
qDebug()
message just after theemit pobjModule->sendJSON(objJSON);
- Write a
qDebug()
message at the start just after theclsModule::onSendJSON()
Questions:
- When you run your program, which debug messages above get printed to output?
- Which thread does your
clsModule
object live in? - Which thread do you call
clsJSON::sendAck()
from? - Why does
clsModule
inheritQProcess
?
- Write a
-
@KroMignon said in Signal and Slot connected by slot not called?:
I am not an English native speaker, so I try to explain the best I can.
Neither am I .
Telling me I do not understand what you wrote is not the subject of discussion.
And it works BOTH ways.Let me try it another way - "emit" is not a keyword.
It is a macro and has a purpose / function in the code.
Its placement is important.BUT if majority of forum participators will keep downgrading "emit" to "sugar" it does not mean such attitude is the best.
Just to make sure - I object ONLY to your treatment of "emit" , I have no comment to the rest of you post.
-
@AnneRanch said in Signal and Slot connected by slot not called?:
Let me try it another way - "emit" is not a keyword.
true
It is a macro
true(ish)
and has a purpose / function in the code.
false
Its placement is important.
false
here's the definition of emit
#ifndef QT_NO_EMIT # define emit #endif
its quite literally expands to nothing
-
@AnneRanch said in Signal and Slot connected by slot not called?:
It is a macro and has a purpose / function in the code.
It's just for debug purposes and to increase the readability. You can say from looking at the emit, that you "call" (or emit) a signal next. Without, it would be hard(er) to say, where exactly you emit your signals. You would need to follow the trace of every signal.
-
@JKSH said in Signal and Slot connected by slot not called?:
- Write a
qDebug()
message just after theQObject::connect(this, &clsModule::sendJSON, this, &clsModule::onSendJSON);
. - Write a
qDebug()
message just after theemit pobjModule->sendJSON(objJSON);
- Write a
qDebug()
message at the start just after theclsModule::onSendJSON()
Questions:
- When you run your program, which debug messages above get printed to output?
- Which thread does your
clsModule
object live in? - Which thread do you call
clsJSON::sendAck()
from? - Why does
clsModule
inheritQProcess
?
I would also suggest adding to the debug log the result of the connection to verify that the connection is actually done correctly. Also, I have a question. On your output log do you see some log related to the module clsModule not being registered using qRegisterMetaType() or anything like that when you try to perform your connection? It may be that we need to register this module as a meta type in order to use it on the connections.
- Write a
-
@rrlopez , what makes you say I need to register clsModule as a type? I don't pass that as a signal parameter I only pass QJsonObject.
-
I was just asking if you had a message on your output log. If you don't get that message then you don't need to register clsModule as a type. What interest me the most is the result of the connection. If you create a QMetaObject::Connection object and assign it to the connection you're trying to do, is it valid? you can check that by doing something like this:
QMetaObject::Connection testConnection = QObject::connect(this, &clsModule::sendJSON, this, &clsModule::onSendJSON); if (!testConnection) { // handle testConnection invalid case (or print error message) }