[Interest] QFutureWatcher not emitting signals

Bob Hood bhood2 at comcast.net
Thu Nov 24 04:16:16 CET 2016


I did some Googling about this, and found a LOT of hits about QFutureWatcher 
not emitting its signals (like finished()) when the QFuture it's watching 
completes.  However, in all cases I've seen, people were using an auto version 
of QFutureWatcher which dropped out of scope on them (i.e., allocated on the 
local stack). Allocating it on the heap seemed to solve all problems I found.

Well, it isn't solving it for me.  I'm using Qt 5.6.2.  I have a simple 
tasklet class that performs a discrete function in a separate thread 
independent of the main process.  Its basic structure looks like this:

Definition:

     class Tasklet : public QObject
     {
         Q_OBJECT
     public:
Tasklet(...args...);
         ~Tasklet();

     signals:
         void    signal_result(const QString& reference, bool result);

     private slots:
         void    slot_future_finished();

     private:    // methods
         bool    run();

     private:    // data members
         ...args...

         QFutureWatcher<bool>*   watcher;
     };

Implementation:

     Tasklet::Tasklet(...args...) : ...init...
     {
         QFuture<bool> future = QtConcurrent::run(this, &Tasklet::run);
         watcher = new QFutureWatcher<bool>();
         connect(watcher, &QFutureWatcher<bool>::finished, this, 
&Tasklet::slot_future_finished);
         watcher->setFuture(future);
     }

     bool Tasklet::run()
     {
         ...processing...
         return true;
     }

     void Tasklet::slot_future_finished()
     {
         emit signal_result(reference, watcher->result());
         watcher->deleteLater();
     }

Tasklet::slot_future_finished() is NEVER called. I've verified that the 
connect() returns true, tried using the old-style syntax for connect, and I've 
also tried having a class member for QFutureWatcher instead of allocating it 
on the heap. No joy.

Can another pair of eyes see what am I doing wrong here?



More information about the Interest mailing list