P
P
Pavel K2021-03-27 01:04:12
Qt
Pavel K, 2021-03-27 01:04:12

How to work with threads in Qt by directly calling slots, but what would they end up in its queue?

There is an object in the thread that uses signals-slots internally, in general, an event queue.

The problem is that for each method call from another thread, either declare a signal and connect a slot, or use QMetaObject::invokeMethod , which greatly inflates the call in case of passing parameters.

So, is there any "approach"/pattern so that when slots are directly called from another thread, they are called inside the queue of this thread?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ighor July, 2021-03-27
@PavelK

If you need to wait for a response then here:
Qt::BlockingQueuedConnection
https://doc.qt.io/qt-5/qt.html#ConnectionType-enum
at runtime both threads will be blocked
And if you do not need to wait then it is safe to call signals directly from other threads that are connected to their object via Qt::QueuedConnection
And if the signal is sent from qmetaobject::invokeMethod to the remote class, then there will be a crash. So this should be avoided.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question