ProEns08 ProEns08 - 4 months ago 22
C++ Question

Qt- how to run two slots simultaneously without explicitly implementing threads

I have two Qt slots that are connected to the same signal.

I must run them in parallel without explicitly using Qt multi-threading.

I searched if Qt has provided a solution to do that impliciltly, But I did not find.

is there any solution to do that in Qt?


You need to connect your signal to slot() and use QtConurrent to do all work

#include <QtConcurrent>
#include <QFuture>
void MyClass::slot()
    QFuture <void> future1, future2;
    future1 = QtConcurrent::run(this,&MyClass::slot1);
    future2 = QtConcurrent::run(this,&MyClass::slot2);

You need to use the concurrent module. In the .pro file, add:

QT += concurrent