Details
-
Suggestion
-
Resolution: Out of scope
-
P3: Somewhat important
-
None
-
None
Description
Simple, non-template QObject member functions, available on all platforms:
runInBackgroundThread(const char * slot, ... args);
runInObjectThread(const char * slot, ... args);
cancelAll();
- Monitors the event loop queue and ajusts the number of threads to prevent overloading the ObjectThread.
- Blocks until all tasks have finised when the object is deleted.
Example:
void ImageViewer::loadFiles(const QStringList &files)
{
foreach (QString &file, files)
runInBackgroundThread("decodeFile", Q_ARG(QString, file));
}
QImage ImageViewer::decodeFile(const QString &fileName)
{
QImage image(fileName);
runInObjectThread("addImage", Q_ARG(QImage, image));
}
void ImageViewer::addImage(const QImage &image)
{
layout()->addWidget(new QLabel(image));
update();
}
Distributed programming add-on
runInDistributedThread(const char * slot, ... args);