preferred way of Calling QObject method from different thread and same thread

97 Views Asked by At

I want to call a QObject method from a different thread (Qt::QueuedConnection) if my app is multithreaded and from the same thread (Qt::DirectConnection) if my app is running on a single thread.

I found it could be achieved in two way 1)signal/slot 2)QMetaObject::invokeMethod using Qt::AutoConnection, but I would like to know which one is preferred and is there any performance difference between them?

  1. Signal/slot Qt::AutoConnection:

Signal/slot way

  1. QMetaObject::invokeMethod Qt::AutoConnection:

enter image description here

There is already an existing code base which is done with signal/slot way, but it's quite difficult to read. Is it worth refactoring it with QMetaObject::invokeMethod?

function arguments could be a custom type too.

0

There are 0 best solutions below