Qt: Specifying multiple connection types with QObject::connect

MistyD

I wanted to know if it is possible to specify multiple connection types. For example, I want my connection type to be a queued connection and a unique connection. Is it possible to specify that in one statement ?

QObject::connect(ptrSender,SIGNAL(..),ptrReceiver,SLOT(...),Queued-and-unique)

Update :

Following the suggestion of the posters:

I tried using Qt::QueuedConnection | Qt::UniqueConnection but I get

 `Error 1   error C2664: 'QMetaObject::Connection QObject::connect(const QObject *,const char *,const QObject *,const char *,Qt::ConnectionType)' : cannot convert parameter 5 from 'int' to 'Qt::ConnectionType'
lpapp

Is it possible to specify that in one statement ?

In theory, it seems to be possible for your scenario. At least, you can read the docs documentation about it.

Qt::UniqueConnection 0x80 This is a flag that can be combined with any one of the above connection types, using a bitwise OR. When Qt::UniqueConnection is set, QObject::connect() will fail if the connection already exists (i.e. if the same signal is already connected to the same slot for the same pair of objects). This flag was introduced in Qt 4.6.

Based on the aforementioned documentation, you would write something like this:

#include <QCoreApplication>

int main(int argc, char **argv)
{
    QCoreApplication coreApplication(argc, argv);
    QObject::connect(&coreApplication, SIGNAL(aboutToQuit()), &coreApplication, SLOT(quit()), static_cast<Qt::ConnectionType>(Qt::QueuedConnection | Qt::UniqueConnection));
    return coreApplication.exec();
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Qt connect() without QObject or slots

From Dev

Qt QObject::connect() function cannot be connected

From Dev

Typescript: specifying multiple callback types in a union

From Dev

QObject::connection(const QObject*, const char*, const char*, Qt::ConnectionType) "Cannot convert argument 3 from 'fileProcessor' to const QObject *"

From Dev

QObject* context in QObject::connect function

From Dev

QObject connection function

From Dev

No matching function for QObject::connect

From Dev

QObject::connect in QRunnable - console

From Dev

Error with QObject::connect()

From Dev

No matching function for QObject::connect

From Dev

QObject::connect: No such slot

From Dev

QObject::connect: No such signal while connecting qml signals in c++ Qt 5.3

From Dev

Registering common Qt meta types in multiple DLLs

From Dev

Qt Multiple Types of Styles for an item (QLabel, QPushbutton, ...)

From Dev

Registering common Qt meta types in multiple DLLs

From Dev

Qt Multiple Types of Styles for an item (QLabel, QPushbutton, ...)

From Dev

Multiple inheritance of QObject

From Dev

Qt: Child QObject during deconstruction?

From Dev

Qt : No such slot QObject::SlotName(QNetworkReply*)

From Dev

QT build QWidget, QObject Errors

From Dev

A function wrapper around QObject::connect

From Dev

Is there a tidier way to connect many Qt widgets of different types to the same slot?

From Dev

Can Qt arrange for QObject* to be set to nullptr when QObject is destroyed?

From Dev

Can Qt arrange for QObject* to be set to nullptr when QObject is destroyed?

From Dev

Call generic Method with multiple generic Types without specifying every single generic Type

From Dev

Specifying schema in SQL server connection

From Dev

Specifying password in MySQL connection string

From Dev

Specifying multiple ordering rules

From Dev

Qt UI to Arduino Serial connection. Setup called multiple times

Related Related

  1. 1

    Qt connect() without QObject or slots

  2. 2

    Qt QObject::connect() function cannot be connected

  3. 3

    Typescript: specifying multiple callback types in a union

  4. 4

    QObject::connection(const QObject*, const char*, const char*, Qt::ConnectionType) "Cannot convert argument 3 from 'fileProcessor' to const QObject *"

  5. 5

    QObject* context in QObject::connect function

  6. 6

    QObject connection function

  7. 7

    No matching function for QObject::connect

  8. 8

    QObject::connect in QRunnable - console

  9. 9

    Error with QObject::connect()

  10. 10

    No matching function for QObject::connect

  11. 11

    QObject::connect: No such slot

  12. 12

    QObject::connect: No such signal while connecting qml signals in c++ Qt 5.3

  13. 13

    Registering common Qt meta types in multiple DLLs

  14. 14

    Qt Multiple Types of Styles for an item (QLabel, QPushbutton, ...)

  15. 15

    Registering common Qt meta types in multiple DLLs

  16. 16

    Qt Multiple Types of Styles for an item (QLabel, QPushbutton, ...)

  17. 17

    Multiple inheritance of QObject

  18. 18

    Qt: Child QObject during deconstruction?

  19. 19

    Qt : No such slot QObject::SlotName(QNetworkReply*)

  20. 20

    QT build QWidget, QObject Errors

  21. 21

    A function wrapper around QObject::connect

  22. 22

    Is there a tidier way to connect many Qt widgets of different types to the same slot?

  23. 23

    Can Qt arrange for QObject* to be set to nullptr when QObject is destroyed?

  24. 24

    Can Qt arrange for QObject* to be set to nullptr when QObject is destroyed?

  25. 25

    Call generic Method with multiple generic Types without specifying every single generic Type

  26. 26

    Specifying schema in SQL server connection

  27. 27

    Specifying password in MySQL connection string

  28. 28

    Specifying multiple ordering rules

  29. 29

    Qt UI to Arduino Serial connection. Setup called multiple times

HotTag

Archive