views:

82

answers:

4

I am learning to program using Qt framework. When I writes some code have signals and slots involved, the events didn't seem to fire and the signals and slots didn't seem to work. It really me make me annoyed. Can you give me some cautions and warnnings about signals and slots in Qt?

slot declarations:

private slots:
            void onFtpCmdFinish(int cmdId, bool error);
            void onRealtimeFtpCmdsDone(bool error);

connection code:

   ftpHandle = new QFtp( this );
   connect(ftpHandle, SIGNAL(commandFinished(int, bool)), this, SLOT(onFtpCmdFinish(int, bool)));

   connect(ftpHandle, SIGNAL(done(bool)), this, SLOT(onRealtimeFtpCmdsDone(bool)));

Thank you in advance!

+2  A: 

In the future, if you ever happen to run into problems with your Qt signals and slots again, the contents of the following blog entry can turn out to be a real life-saver (or at least a very good starting point for your investigations):

http://samdutton.wordpress.com/2008/10/03/debugging-signals-and-slots-in-qt/

It meticulously lists 20 ways to debug/troubleshoot your signals and slots; follow this list and chances are high that you will eventually find out what's wrong.

I hope that helps.

Greg S
+2  A: 

You can only detect failed connect() at runtime.

A couple of tips:

defining QT-FATAL-WARNINGS=1 will cause Qt to assert and quit whenever it gets a connect that doesn't match.

Or wrapping each connect in:
bool ok = connect(……); QASSERT( ok);

Martin Beckett
+1  A: 

Always check the return type, if its true then CONNECT successful else some thing wrong..

Shadow
+1  A: 

Don't forget about the fifth argument Qt::ConnectionType if you will write multithreaded applications

Andrew