What do you do if you think that you've correctly connected a signal to a slot and yet your slot's not being fired?
Here's a bunch of things you can try:
connect
code, the emit code, and the slot code is reached. (Odds are one of them isn't.)connect(sender, SIGNAL(someSignal(type)), receiver, SLOT(received(type)))
const
and the reference specifications in the arguments; the metaobject compiler strips them anyway.QObject
and that you have Q_OBJECT
declared in your class definition. Remember, you need to do both.QObject
declaration in your header, rerun qmake
and rebuild.connect
before you invoke any functions that fire the signal.Usually, the problem is pretty easy to track down, especially if you check the log and the signal and slot declarations closely. A common mistake is to wire a signal to a slot that's not been declared a slot, so check your headers closely!
Another thing to note: are your signals not disconnecting when they should? Consider the following line:
disconnect(object);
The preceding line is not the same as the following:
disconnect(object, 0, 0, 0);
This makes perfect sense when you look at the overloaded function definitions for disconnect
, which read:
bool QObject::disconnect ( const QObject * receiver, const char * method = 0 ).
Calling disconnect
and passing only an object disconnects all the signals, rather than just the signal that you choose.