Results 1 to 5 of 5

Thread: Problem with getting QFuture and QFutureWatcher working properly

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2013
    Posts
    3
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Problem with getting QFuture and QFutureWatcher working properly

    Hey all,

    I'd like to ask for a little help as I followed some quick tutorials on how to get another thread in my app working. The thing I'm doing is a kind of organiser with calendar that has ability to popup reminders for the user and I'd like to use different thread for checking if there isn't any task to remind the user of and if there is show a popup with info about it. I figured a way to do it from some websites and this is what I've come up with, but unfortunately app is not responding when I try to run it:


    Qt Code:
    1. QFuture<Task*> future = QtConcurrent::run(this, &MainWindow::checkReminders);
    2.  
    3. popupTask = future.result();
    4.  
    5. QFutureWatcher<Task*> watcher;
    6. watcher.setFuture(future);
    7.  
    8. connect(&watcher, SIGNAL(finished()), this, SLOT(popupReminder()));
    To copy to clipboard, switch view to plain text mode 

    Above is set in MainWindow constructor.

    I haven't already connected the popupTask variable to popupReminder() method, because I wanted to make it work first before providing the popup with the information to show.

    Here is MainWindow::checkReminders() method:

    Qt Code:
    1. Task* MainWindow::checkReminders() {
    2. do {
    3. for(int i = 0; i < daysList.count(); i++) {
    4. for(int j = 0; j < daysList[i].getListCount(); j++) {
    5. QDateTime current = QDateTime::currentDateTime();
    6. if(current == *daysList[i].getTaskAtIndex(j)->getReminderTime() &&
    7. !daysList[i].getTaskAtIndex(j)->ifDone() &&
    8. daysList[i].getTaskAtIndex(j)->ifNeededReminder()) {
    9. daysList[i].getTaskAtIndex(j)->turnOffReminder();
    10. return daysList[i].getTaskAtIndex(j);
    11.  
    12. }
    13. }
    14. }
    15. } while (true);
    16.  
    17. }
    To copy to clipboard, switch view to plain text mode 

    and finally the popupReminder() method:

    Qt Code:
    1. void MainWindow::popupReminder() {
    2. QMessageBox::StandardButton reply;
    3. reply = QMessageBox::information(this, tr("QMessageBox::information()"), MESSAGE1);
    4. }
    To copy to clipboard, switch view to plain text mode 

    Earlier I used checkReminders as a void method that just made the window pop up itself, but I've read somewhere that it is better not to make multiple threads take care of GUI, so I thought I'll give it a try with QFutureWatcher. If someone could point out what I'm doing wrong I'd be grateful.
    Last edited by jahsiotr; 13th January 2013 at 12:36.

Similar Threads

  1. Replies: 1
    Last Post: 7th December 2011, 00:49
  2. QFutureWatcher finished() signal not working
    By DiamonDogX in forum Qt Programming
    Replies: 13
    Last Post: 25th October 2011, 18:27
  3. QFutureWatcher finished without even starting a QFuture...
    By Zweistein in forum Qt Programming
    Replies: 0
    Last Post: 22nd September 2011, 14:30
  4. memcpy not working properly
    By sattu in forum Qt Programming
    Replies: 3
    Last Post: 26th October 2010, 23:33
  5. ScrollZoomer not working properly..
    By Raghaw in forum Qwt
    Replies: 1
    Last Post: 30th October 2009, 06:51

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
  •  
Qt is a trademark of The Qt Company.