Qtconcurrent finish signal ...
-
I would like to get the finisched signal from my qtconcurrent <void> to use it in a signal slot mechanism ... i need to use qtfuturewatcher and qtfuture? .... my void read some file on lan and charge the file name on Qlist .... when the operation is finish I need to have finish signal because I have a lot of these type of operation (10) so i can update my progress bar every action was finisch ..... or reuse the same void for reading file to other folder ....
regards
giorgio -
@gfxx You should really use correct wording: "qtconcurrent <void>" - do you mean QtConcurrent::run? "or reuse the same void" - use same void, what does it mean?
So, do you use QtConcurrent::run? If so, then yes you need to use QFuture and QFutureWatcher. -
-
@jsulm .... I think I use these structure of code:
#include <QCoreApplication> #include <qtconcurrentrun.h> #include <QThread> #ifndef QT_NO_CONCURRENT void myRunFunction(QString name) { for(int i = 0; i <= 5; i++) { qDebug() << name << " " << i << "from" << QThread::currentThread(); } } int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QFuture<void> t1 = QtConcurrent::run(myRunFunction, QString("A")); QFuture<void> t2 = QtConcurrent::run(myRunFunction, QString("B")); QFuture<void> t3 = QtConcurrent::run(myRunFunction, QString("C")); t1.waitForFinished(); t2.waitForFinished(); t3.waitForFinished(); return a.exec(); } #else #include <QLabel> int main(int argc, char *argv[]) { QApplication app(argc, argv); QString text("Qt Concurrent is not yet supported on this platform"); QLabel *label = new QLabel(text); label->setWordWrap(true); label->show(); qDebug() << text; app.exec(); } #endif
in these case QFuture<void> t1 = QtConcurrent::run(myRunFunction, QString("A")); I think to use these row of code. So I better re-write my question:
For bring "isfinished SIGNAL" in these case I must use QFutureWatcher?
You are in right ... my terminology is wrong .... I had to say QFuture <void> and not Qconcurrent <void> .... or say to use a Void with Qcouncurrent and get an isfinished signal ...
So my terminology is bad as my english :)) .... So I do not think it's such a bad thing to spend my money on an English course.
Have a Happy day ... and Thanks a lot.
Giorgio
-
@gfxx If I'm not totally wrong, than you can simply emit a Signal at the end of your run funtion!
void myRunFunction(QString name) { for(int i = 0; i <= 5; i++) { qDebug() << name << " " << i << "from" << QThread::currentThread(); } emit runIsDone(); }
Just connect that Signal to a Slot and go from there. To be sure give the Connect a
Qt::QueuedConnection
as 5th parameter. -
@J.Hilk said in Qtconcurrent finish signal ...:
f I'm not totally wrong, than you can simply emit a Signal at the end of your run funtion!
you are in right ... these is my ideas too .... an in the afternoon I try .... but I would know if there are some other SIGNAL type already ready, without make a new one .....
regards
giorgio -
Structure is more or less like this:
QFuture<MyClass> future = QtConcurrent::run(function,..); QFutureWatcher<MyClass>* pWatcher = new QFutureWatcher(parent); pWatcher->setFuture(future); // Now I can use signals emitted by pWatcher
-
@Asperamanca thanks.