Question about Qt::QueuedConnection
-
I'm curious about the behavior of signals when connected to slots via Qt::QueuedConnection, specifically what if you call to emit the same signal from two different threads.
i.e.:
class A : public QObject { Q_OBJECT public: A() { auto worker = new B(); auto thread = new QThread(); worker.moveToThread(thread); connect(this, &A::fireTestSignal, worker, &B::testSlot); } void fireTestSignal() { emit fireTestSignal(); } signals: void testSignal(); }; class B : public QObject { Q_OBJECT public: B() { } public slots: void testSlot() { qInfo() << "Test"; }; }; int main() { //Assume QCoreApplication created here const auto testClass = std::make_shared<A>(); QtConcurrent::run(QThreadPool(), [testClass]() { testClass->fireTestSignal(); }); testClass->fireTestSignal(); return 0; }Does firing the same signal from two threads cause issues if the connection is a Queued Connection type? Is calling the signal itself thread safe?
Thanks!
-
- No
- Yes