Signal and Slot
-
Hi, see Signals & Slots in the documentation for detailed explanation.
-
QObject::connect(SignalSender,SIGNAL(yoursignal),SignalReceiver,SLOT(yourslot));ex:
MainWindow w; myClass myObj; QObject::connect(&w,SIGNAL(someSignal),&myObj,SLOT(someSlotinMyClass);if you use pointer then don't necessary '&'
-
QObject::connect(SignalSender,SIGNAL(yoursignal),SignalReceiver,SLOT(yourslot));ex:
MainWindow w; myClass myObj; QObject::connect(&w,SIGNAL(someSignal),&myObj,SLOT(someSlotinMyClass);if you use pointer then don't necessary '&'
@Emre-MUTLU It is better to use newer Qt5 connect syntax as it gives you compile time errors if you do something wrong instead of runtime errors.
-
connect(sender, &sender::Signal, this, &MyObj::someSLOT);like this right ?
-
connect(sender, &sender::Signal, this, &MyObj::someSLOT);like this right ?
@Emre-MUTLU said in Signal and Slot:
connect(sender, &sender::Signal, this, &MyObj::someSLOT);
Almost:
connect(sender, &SenderClass::Signal, this, &MyObj::someSLOT); -
This post is deleted!
-
sorry, i don't ask the syntax of signal and slot. I want to understand meta-object compiler. Signal and slot are macros and they are connected by meta-object, right?
@kamejoko said in Signal and Slot:
I want to understand meta-object compiler. Signal and slot are macros and they are connected by meta-object, right?
You can start here: https://woboq.com/blog/how-qt-signals-slots-work.html (at the end of this article, there is a link to Part 2)
-
sorry, i don't ask the syntax of signal and slot. I want to understand meta-object compiler. Signal and slot are macros and they are connected by meta-object, right?
@kamejoko said in Signal and Slot:
Signal and slot are macros
No, they are methods. Slot is written by programmer. Signal is generated for you by moc and you can see how it is implemented by looking into generated header file. QObject::connect just memorises that the slot needs to be called when the signal is called.
-
@kamejoko said in Signal and Slot:
I want to understand meta-object compiler. Signal and slot are macros and they are connected by meta-object, right?
You can start here: https://woboq.com/blog/how-qt-signals-slots-work.html (at the end of this article, there is a link to Part 2)
-
@kamejoko said in Signal and Slot:
Signal and slot are macros
No, they are methods. Slot is written by programmer. Signal is generated for you by moc and you can see how it is implemented by looking into generated header file. QObject::connect just memorises that the slot needs to be called when the signal is called.
@jsulm thanks. that's exactly is which i want to know. Could you tell me how many type of signal and slots mechanism? I read at doc.qi.io and i see there are two signal and slots mechanism. One is "Signals and slots with default argument". Two is "Advance signals and slots Usage". I don't know whether i'm true
-
@jsulm thanks. that's exactly is which i want to know. Could you tell me how many type of signal and slots mechanism? I read at doc.qi.io and i see there are two signal and slots mechanism. One is "Signals and slots with default argument". Two is "Advance signals and slots Usage". I don't know whether i'm true
@kamejoko said in Signal and Slot:
Could you tell me how many type of signal and slots mechanism?
I'm not sure what you're asking.
There is only one type of signals/slots, but two different ways to connect them:- The old connect syntax using SIGNAL and SLOT macros
- The newer and better connect syntax using function pointers
Signals and slots can have 0..n parameters, like any other function/method.
-
@kamejoko said in Signal and Slot:
Could you tell me how many type of signal and slots mechanism?
I'm not sure what you're asking.
There is only one type of signals/slots, but two different ways to connect them:- The old connect syntax using SIGNAL and SLOT macros
- The newer and better connect syntax using function pointers
Signals and slots can have 0..n parameters, like any other function/method.