Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Auto can I check the result of a connect() with Qt::AutoConnection



  • I'm having some weird difference between the same program compiled in Qt 4.8 and Qt 5.15
    and I suspect that Qt::AutoConnection doesn't behave the same in both case.
    Is there a way I can check if the connection resulted in Qt::DirectConnection or Qt::QueuedConnection?
    Thanks!


  • Lifetime Qt Champion

    Hi,

    Unless you force the type, it will be selected at run time. The objects being in different threads is the key for a queued connection.



  • Can this be checked at runtinme? connect() returns a handle, but it doesn't contains this kind of information.


  • Moderators

    @JulienMaille said in Auto can I check the result of a connect() with Qt::AutoConnection:

    I'm having some weird difference between the same program compiled in Qt 4.8 and Qt 5.15
    and I suspect that Qt::AutoConnection doesn't behave the same in both case.

    What weird difference are you seeing?

    The behaviour of Qt::AutoConnection has not changed between Qt 4 and Qt 5.

    Is there a way I can check if the connection resulted in Qt::DirectConnection or Qt::QueuedConnection?

    Check QObject::thread() for both the sender and receiver. If both use the same thread, then the connection is Qt::DirectConnection. If they use different threads, then the connection is Qt::QueuedConnection. This is what @SGaist meant.

    You can also call call QThread::currentThread() in the slot to see which thread ran the slot.



  • Thanks to both of you. I believe my issue has to do with processEvent() and not the connect. I will open another topic


Log in to reply