Results 1 to 3 of 3

Thread: which one has finished with QFutrueWatcher

  1. #1
    Join Date
    Jun 2010
    Posts
    38
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Question which one has finished with QFutrueWatcher

    Hi , all

    I need compute some different data at one time ,so I use the QtConcurrent:run to

    compute the data , and use QFutrueWatcher to monitor the computing state.

    Here is the a section of the code.
    Qt Code:
    1. **.h
    2.  
    3. QVector<QFuture<void> *> ftVec;
    4. QVector<QFutureWatcher<void> *> ftwVec;
    5.  
    6.  
    7. **.cpp
    8.  
    9. //begin a new computation.
    10. ftVec << new QFuture<void>;
    11. ftwVec << new QFutureWatcher<void>;
    12.  
    13. connect(ftwVec[num], SIGNAL(finished()),this, SLOT(getresultFunction()));
    14.  
    15. *ftVec[num] = QtConcurrent::run(this,&MainWindow::computeFuntion);
    16. ftwVec[num]->setFuture(*ftVec[num]);
    17. num++;
    To copy to clipboard, switch view to plain text mode 

    I want know which watcher is finished when it execute the function getresultFunction.

    Give me some suggestions. Thanks..!

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: which one has finished with QFutrueWatcher

    The most correct way to do this is to use a QSignalMapper

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

    Default Re: which one has finished with QFutrueWatcher

    You are probably overcomplicating things. Try this approach:

    Qt Code:
    1. void MainWindow::computeFunction(const MyArg &arg) {
    2. doSomethingWith(arg);
    3. } // static
    4.  
    5. QList<MyArg> computations;
    6. fillDataInto(computations);
    7. QFutureWatcher watcher;
    8. connect(&watcher, SIGNAL(resultReadyAt(int)), ...);
    9. QFuture<void> future = QtConcurrent::map(computations, MainWindow::computeFunction);
    10. watcher.setFuture(future);
    To copy to clipboard, switch view to plain text mode 

    You'll get much cleaner design.
    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. QGridLayout: how to know it has finished rendering items?
    By slash_blog in forum Qt Programming
    Replies: 0
    Last Post: 8th June 2010, 12:06
  2. get finished signal from a thread
    By ProTonS in forum Qt Programming
    Replies: 4
    Last Post: 21st August 2009, 14:17
  3. QProcess::finished problems again
    By mdicosimo in forum Qt Programming
    Replies: 2
    Last Post: 23rd January 2009, 21:43
  4. QProcess::finished()
    By T1c4L in forum Qt Programming
    Replies: 11
    Last Post: 9th July 2008, 20:06
  5. Getting the moment when resize is finished
    By m_e in forum Qt Programming
    Replies: 4
    Last Post: 7th November 2007, 21:14

Tags for this Thread

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.