[Qt-interest] QtConcurrent and QFutureWatcher
Marius Roets
roets.marius at gmail.com
Thu Sep 23 16:33:22 CEST 2010
On Thu, Sep 23, 2010 at 4:02 PM, Andre Somers <andre at familiesomers.nl>wrote:
> Op 23-9-2010 14:35, Marius Roets schreef:
> > Hi Everybody,
> >
> > I have this piece of code in a widget, when a button is pressed:
> >
> > MyObject m;
> > QFutureWatcher<void> futureWatcher;
> > connect(&futureWatcher, SIGNAL(finished()), this,
> > SLOT(longExecuteCompleted()));
> > futureWatcher.setFuture(QtConcurrent::run(m, &MyObject::longExecute));
> >
> > It seems to work as expected, except that longExecuteCompleted() never
> > gets called, and I can see from the log files that longExecute() did
> > complete. Is there anything I could missing in MyObject, longExecute()
> > or futureWatcher for this to work.
> The issue is, that your futureWatcher goes out of scope before the
> execution of your longExecute is finished. That means that the
> futureWatcher is destroyed, and the connection deleted. Put your future
> watcher somewhere where it will last long enough to actually signal the
> completion of your task, like on the heap (don't forget to delete it
> when you're done using it) or as a member of your object.
>
> Getting old I think. Thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100923/64d248f2/attachment.html
More information about the Qt-interest-old
mailing list