Results 1 to 5 of 5

Thread: When's SLOT invoked ?

  1. #1
    Join Date
    Nov 2011
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Unhappy When's SLOT invoked ?

    My example:
    Qt Code:
    1. void funcMain()
    2. {
    3. QFtp * ftp = new QFtp(this);
    4. connect(ftp, SIGNAL(listInfo(QUrlInfo)),
    5. this, SLOT(addToList(QUrlInfo)));
    6. .....
    7. ftp->list(); // emit signal listInfo();
    8. .....
    9. return;
    10. }
    11.  
    12. void addToList(QUrlInfo info)
    13. {
    14. //do something
    15. }
    To copy to clipboard, switch view to plain text mode 

    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 ?

  2. #2
    Join Date
    Apr 2010
    Location
    Russian Federation, Kaluga
    Posts
    20
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: When's SLOT invoked ?

    See:
    http://doc.qt.nokia.com/stable/qobject.html#connect-2
    http://doc.qt.nokia.com/stable/qt.ht...nectionType-en

    You need Qt:irectConnection type, i.e.
    Qt Code:
    1. connect(ftp, SIGNAL(listInfo(QUrlInfo)),
    2. this, SLOT(addToList(QUrlInfo)),Qt::DirectConnection);
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Nov 2011
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: When's SLOT invoked ?

    DirectConnection is like AutoConnection

  4. #4
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: When's SLOT invoked ?

    Quote Originally Posted by phtdce View Post
    DirectConnection is like AutoConnection
    Only when sender and receiver are in this same thread.

  5. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: When's SLOT invoked ?

    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)

  6. The following user says thank you to ChrisW67 for this useful post:

    phtdce (23rd November 2011)

Similar Threads

  1. Replies: 15
    Last Post: 11th December 2012, 21:10
  2. Paint() not invoked by QGraphicsScene
    By vanaGte in forum Qt Programming
    Replies: 1
    Last Post: 8th May 2011, 23:44
  3. Replies: 10
    Last Post: 2nd March 2011, 12:25
  4. How to find out whom invoked a slot?
    By vulee in forum Qt Programming
    Replies: 3
    Last Post: 2nd December 2010, 22:55
  5. Replies: 2
    Last Post: 16th September 2010, 12:33

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.