View Full Version : When's SLOT invoked ?

19th November 2011, 04:06
My example:

void funcMain()
QFtp * ftp = new QFtp(this);
connect(ftp, SIGNAL(listInfo(QUrlInfo)),
this, SLOT(addToList(QUrlInfo)));
ftp->list(); // emit signal listInfo();

void addToList(QUrlInfo info)
//do something

When debug, SLOT(addToList) is invoked after funcMain() return. But i want addToList() to be invoked right after statement ftp->list() finish and before funcMain return , so what should i do ? And signal listInfo() is emitted while invoking ftp->list() or after ftp->list() finish or after funcMain() return ?

19th November 2011, 13:06

You need Qt::DirectConnection type, i.e.

connect(ftp, SIGNAL(listInfo(QUrlInfo)),
this, SLOT(addToList(QUrlInfo)),Qt::DirectConnection);

19th November 2011, 15:47
DirectConnection is like AutoConnection

19th November 2011, 16:43
DirectConnection is like AutoConnectionOnly when sender and receiver are in this same thread.

22nd November 2011, 07:57
QFtp::list() is run asynchronously. From the friendly manual:

The function does not block and returns immediately. The command is scheduled, and its execution is performed asynchronously. The function returns a unique identifier which is passed by commandStarted() and commandFinished().
Nothing happens, i.e. no request is sent and hence no responses received, until your program returns to the event loop. You can redesign with asynchronous events in mind, use QCoreApplication::processEvents(), or use a local event loop (QEventLoop)