Results 1 to 2 of 2

Thread: How to use progressTextChanged() signal in QFutureWatcher

  1. #1
    Join Date
    Apr 2009
    Posts
    63
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Windows

    Default How to use progressTextChanged() signal in QFutureWatcher

    I have a task I want to run upon clicking a button. I want the method to be run in a separate thread so as not to hang up the GUI while it is running (the GUI does indeed hang with my current code below). I also want the method running the task to report back text information to be appended to a TextEdit control, e.g. "Starting task...", "Reading file...", "Performing computation...", etc. I've set up a QFuture, QFutureWatcher, etc. but not sure how to actually emit the progressTextChanged signal and not sure why GUI is hanging:

    Qt Code:
    1. //...
    2. //...
    3. QFuture<bool> future = QtConcurrent::run(
    4. this,
    5. &MyClass::runTheTask );
    6.  
    7. QFutureWatcher<bool> watcher;
    8. connect( &watcher, SIGNAL( progressTextChanged( const QString ) ),
    9. this, SLOT( appendMessageToStatusLineEdit( const QString ) ) );
    10. watcher.setFuture( future );
    11. future.waitForFinished();
    12.  
    13. // ...
    14. // ...
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. bool MyClass::runTheTask()
    2. {
    3. // emit progress text signal???
    4.  
    5. // currently I have something like the following:
    6. appendMessageToStatusLineEdit( "Status update..." ); // don't see this happen until the entire task is complete for some reason
    7. // more code
    8. // etc.
    9. }
    10.  
    11. void MyClass::appendMessageToStatusLineEdit( const QString msg )
    12. {
    13. QMetaObject::invokeMethod( this,
    14. "doAppendMessageToStatusLineEdit",
    15. Qt::QueuedConnection,
    16. Q_ARG( QString, msg ) );
    17. }
    18.  
    19. void MyClass::doAppendMessageToStatusLineEdit( const QString msg )
    20. {
    21. _ui->statusTextEdit->append( msg );
    22. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by DiamonDogX; 9th June 2009 at 15:47.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to use progressTextChanged() signal in QFutureWatcher

    It hangs because you call waitForFinished().
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. pthread instead QThread
    By brevleq in forum Qt Programming
    Replies: 8
    Last Post: 23rd December 2008, 07:16
  2. Connection of custon signals/slots
    By brevleq in forum Qt Programming
    Replies: 2
    Last Post: 23rd December 2008, 07:04
  3. Possible signal mapper problem
    By MarkoSan in forum Qt Programming
    Replies: 13
    Last Post: 25th January 2008, 13:11
  4. Replies: 2
    Last Post: 17th May 2006, 21:01

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.