c – Qt:使用QObject :: connect指定多个连接类型

我想知道是否可以指定多种连接类型.例如,我希望我的连接类型是排队的连接和唯一的连接.是否可以在一个语句中指定?
QObject::connect(ptrSender,SIGNAL(..),ptrReceiver,SLOT(...),Queued-and-unique)

更新:

按照海报的建议:

我试过使用Qt :: QueuedConnection | Qt :: UniqueConnection,但我得到

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

解决方法

Is it possible to specify that in one statement ?

在理论上,您的情景似乎是可能的.至少你可以阅读关于它的文档documentation.

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.

基于上述文档,您将会写下如下内容

#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();
}

相关文章

本程序的编译和运行环境如下(如果有运行方面的问题欢迎在评...
水了一学期的院选修,万万没想到期末考试还有比较硬核的编程...
补充一下,先前文章末尾给出的下载链接的完整代码含有部分C&...
思路如标题所说采用模N取余法,难点是这个除法过程如何实现。...
本篇博客有更新!!!更新后效果图如下: 文章末尾的完整代码...
刚开始学习模块化程序设计时,估计大家都被形参和实参搞迷糊...