Results 1 to 6 of 6

Thread: QFutureWatcher signals not firing

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

    Default QFutureWatcher signals not firing

    Has anyone had problems with QFutureWatcher signals not firing? Here's the code:
    Qt Code:
    1. QFutureWatcher<void> watcher;
    2.  
    3. connect(&watcher, SIGNAL(progressRangeChanged(int, int)), this, SLOT(progressRangeChanged(int, int)));
    4. connect(&watcher, SIGNAL(progressValueChanged(int)), this, SLOT(progressValueChanged(int)));
    5. connect(&watcher, SIGNAL(finished()), this, SLOT(finished()));
    6.  
    7. QFuture<dent_vec_t> dent_scan_future = QtConcurrent::mappedReduced(all_joint_scan_params,dent_scan_with_line,&combine_dent_lists);
    8. watcher.setFuture(dent_scan_future);
    9. while (!watcher.isFinished())
    10. {
    11. //Some debug code
    12. int prog1 = watcher.progressMinimum();
    13. int prog2 = watcher.progressMaximum();
    14. int progValue = watcher.progressValue();
    15. }
    16. m_dents = dent_scan_future.result();
    To copy to clipboard, switch view to plain text mode 

    I threw in the debug code to see if there's any progress to report, and there is. Here are my slots:

    Header:
    Qt Code:
    1. public slots:
    2. void finished();
    3. void progressRangeChanged(int, int);
    4. void progressValueChanged(int);
    To copy to clipboard, switch view to plain text mode 

    CPP:
    Qt Code:
    1. void dent_scanner::finished()
    2. {
    3. cout<<"FINISHED"<<endl;
    4. }
    5.  
    6. void dent_scanner::progressRangeChanged(int a, int b)
    7. {
    8. cout<<"PROGRESS RANGE CHANGED: " <<a<<", "<<b<<endl;
    9. }
    10.  
    11. void dent_scanner::progressValueChanged(int a)
    12. {
    13. cout<<"PROGRESS VALUE CHANGED: " <<a<<endl;
    14. }
    To copy to clipboard, switch view to plain text mode 

    This code won't execute no matter what I do. I have the Q_OBJECT macro in the header, and the moc file included at the bottom. The class inherits from QOBject. No errors print out when I connect up the signals and slots (already fixed that problem...)

    I can usually find my way around signals and slots just fine. I probably just made a stupid mistake, but can't seem to figure out what it is. Any thoughts?

  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: QFutureWatcher signals not firing

    Are you sure the following line is correct?
    Qt Code:
    1. QFutureWatcher<void> watcher;
    To copy to clipboard, switch view to plain text mode 

    Shouldn't that be the the following line?
    Qt Code:
    1. QFutureWatcher<dent_vec_t> watcher;
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: QFutureWatcher signals not firing

    Well, I got the signals to fire, but not until everything was done, which defeats the point of monitoring the progress. So here's my new question: how can I actually monitor the progress DURING the threading. Maybe my code is doing something a little strange that won't allow any signals to fire until all the threads are free.


    Added after 1:


    OK this is getting annoying. Calling cancel on the Future returned from mappedReduced doesn't do anything until the entire computation has finished. I give it an array of 100's of items to process in mappedReduced, but it won't cancel until all have been processed. This is because the cancel signal won't get fired until the very end, just like all the other signals I'm dealing with.... Very strange. Anyone had this problem before?
    Last edited by nwest; 3rd December 2010 at 21:07.

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

    Default Re: QFutureWatcher signals not firing

    You are not letting the events be processed with your while() loop.

    [wiki]Keeping the GUI Responsive[/wiki]
    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.


  5. The following user says thank you to wysota for this useful post:

    nwest (3rd December 2010)

  6. #5
    Join Date
    Dec 2010
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QFutureWatcher signals not firing

    Yep, that seems to be it. I guess I just assumed the events would be processed during the threading automatically. I knew it would be something dumb like that.

    It appears each individual thread that's running has to finish before it cancels. So there's no way to cancel a thread during its run. I guess it doesn't want to cause any bad states by killing a thread while it's processing data. If I'm wrong about this, please let me know. It would be great to able to kill a thread before it's finished.

  7. #6
    Join Date
    Sep 2010
    Posts
    145
    Thanks
    1
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QFutureWatcher signals not firing

    No, you're right. Killing a thread, such as calling TerminateThread(), allows no chance to clean up anything (which includes locking primitives!).

Similar Threads

  1. QFutureWatcher finished() signal not working
    By DiamonDogX in forum Qt Programming
    Replies: 13
    Last Post: 25th October 2011, 18:27
  2. QProcess finished slot not firing
    By doggrant in forum Qt Programming
    Replies: 0
    Last Post: 10th November 2010, 13:09
  3. QT VS C++ 2005, QPushButton NOT FIRING!!!!!
    By harleyskater in forum General Programming
    Replies: 20
    Last Post: 12th June 2010, 02:15
  4. QSocketNotifier activated() not firing
    By jflatt in forum Qt Programming
    Replies: 1
    Last Post: 10th July 2009, 20:10
  5. How to use progressTextChanged() signal in QFutureWatcher
    By DiamonDogX in forum Qt Programming
    Replies: 1
    Last Post: 9th June 2009, 15:41

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.