PDA

View Full Version : Signal and slot



Sheng
16th October 2008, 20:42
Please correct me if I am wrong, my understanding about signal and slot is as long as both objects are derived from Q_OBJECT, and signal/slot are define in their class definition, they can be connected anywhere these objects exist.
For example, I can define all the connections in main.cpp which handles many objects, is that right?

JimDaniel
16th October 2008, 21:46
More or less, but its not right to say "objects are derived from Q_OBJECT" as that is a macro definition and not a class - QObject is the class. To use signals/slots you need to have objects which derive from QObject and include the Q_OBJECT macro.

Sheng
17th October 2008, 16:35
More or less, but its not right to say "objects are derived from Q_OBJECT" as that is a macro definition and not a class - QObject is the class. To use signals/slots you need to have objects which derive from QObject and include the Q_OBJECT macro.

Thanks, I find Derived from QWidget might be a better idea since it allows using QMessageBox, while QObject does not.

JimDaniel
17th October 2008, 18:46
Sure, you can do that. QWidget itself derives from QObject.