我想知道是否可以指定多种连接类型.例如,我希望我的连接类型是排队的连接和唯一的连接.是否可以在一个语句中指定?
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(); }