Results 1 to 4 of 4

Thread: QFutureWatcher doesn't get finished signal

  1. #1
    Join Date
    Sep 2012
    Posts
    34
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default QFutureWatcher doesn't get finished signal

    Hi,


    My program starts new thread for making PDF files having many pictures and other heavy stuff. During creation of those PDFs, I want that the main window to show animation indicating that PDF is on progress and stop the animation once PDF is ready.


    Problem is that it seems that my QFutureWatcher never receives the finished signal and go to the pysayta_lataus_animaatio() function. I've used hours and hours trying to resolve what's wrong here but cannot figure it out.


    Can someone see what is wrong with this code? Thanks in advance!

    mainwindow.h
    Qt Code:
    1. public slots:
    2.  
    3. void pysayta_lataus_animaatio();
    To copy to clipboard, switch view to plain text mode 

    mainwindow.cpp
    Qt Code:
    1. void MainWindow::on_pB_yhtio_laskut_clicked() // slot, called when user selected push button for creating PDF
    2. {
    3. TRACE("-> void MainWindow::on_pB_yhtio_laskut_clicked()");
    4.  
    5. QFutureWatcher lataus_watcher;
    6. connect(&lataus_watcher, SIGNAL(finished()), this, SLOT(pysayta_lataus_animaatio()));
    7. QFuture future = QtConcurrent::run(this, &MainWindow::PDF_laskut_yhtio);
    8. lataus_watcher.setFuture(future);
    9. TRACE("Watcher set.");
    10.  
    11. QMovie *movie = new QMovie(":kuvat/lataa_pieni.gif");
    12. QLabel *processLabel = new QLabel(this);
    13. processLabel->setMovie(movie);
    14. processLabel->setFixedSize(50,50);
    15. processLabel->move(430,93);
    16. movie->start();
    17. processLabel->show();
    18. TRACE("animation started");
    19. }
    20.  
    21. void MainWindow::pysayta_lataus_animaatio()
    22. {
    23. TRACE("-> void MainWindow::pysayta_lataus_animaatio()"); // TRACE writes given QString to a log file.
    24. //TBD: stop the animation
    25. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,688
    Thanks
    13
    Thanked 1,598 Times in 1,526 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QFutureWatcher doesn't get finished signal

    As soon as execution leaves the slot the QFutureWatcher and QFuture objects (line 5 and 7) are destroyed because they go out of scope. Destroying the watcher removes the connection. You need to ensure these object's have a lifetime longer than the process they are watching.

    Also, the memory allocation at line 11 is a memory leak... the label does not take ownership of the movie.

  3. #3
    Join Date
    Sep 2012
    Posts
    34
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QFutureWatcher doesn't get finished signal

    Thanks for you reply. It started working after moving creation QFutureWatcher and QFuture objects next to #include lines. Thanks again!

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

    Default Re: QFutureWatcher doesn't get finished signal

    Quote Originally Posted by Mobility View Post
    Thanks for you reply. It started working after moving creation QFutureWatcher and QFuture objects next to #include lines. Thanks again!
    That's not a good approach. Create the future watcher using the new operator in the function where you had it before. The future object can be created on the stack, since it will be copied to the watcher.
    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. QFutureWatcher finished() signal not working
    By DiamonDogX in forum Qt Programming
    Replies: 13
    Last Post: 25th October 2011, 19:27
  2. QFutureWatcher finished without even starting a QFuture...
    By Zweistein in forum Qt Programming
    Replies: 0
    Last Post: 22nd September 2011, 15:30
  3. Replies: 3
    Last Post: 13th July 2011, 09:24
  4. Replies: 3
    Last Post: 7th April 2011, 12:09
  5. QUrlOperator doesn't emit finished signal
    By hayati in forum Qt Programming
    Replies: 16
    Last Post: 26th March 2007, 21:25

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.