[Qt-interest] QConcurrent, QFutureWatcher, Multi-thread programming question

Li-Chung Chang clc168 at gmail.com
Tue May 4 07:47:55 CEST 2010


Multi-thread programming:

The imagescaling sample code in qt/examples/qtconcurrent/imagescaling is
good example for using QtConcurrent::mapped(*sequence,
MapFunction*)/QFutureWater<T>.
In this example, If user want to start another mapped request, it check
isRunning() first and cancel()+waitForFinished() if needed.

    // qt/examples/qtconcurrent/imagescaling/magescaling.cpp
    ...
    // Cancel and wait if we are already loading images.
    if (imageScaling->isRunning()) {
        imageScaling->cancel();
        imageScaling->waitForFinished();
    }
    ...
    // Use mapped to run the thread safe scale function on the files.
    imageScaling->setFuture(QtConcurrent::mapped(files, scale));


My question is that if images are large(Maybe 15~20MB) and I started "open
images", clicked "cancel" button immediately and clicked "open images"
again. It take a long time during
QFutureWatcher::cancel()+QFutureWatcher::waitForFinished() in  void
Images::open() function.

1. How do I reduce the time of
"QFutureWatcher::cancel()+QFutureWatcher::waitForFinished()" ?

2. If I don't want to cancel the the asynchronous computation, I just want
to append new images for displaying. QConcurrent can support changing
mapping sequence dynamically during asynchronous computation is running?



Ziv
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100504/72aa6e20/attachment.html 


More information about the Qt-interest-old mailing list