ProEns08 ProEns08 - 1 year ago 95
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?

Answer Source

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download