加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-16 05:51:42 所属栏目:百科 来源:网络整理
导读:我想知道是否可以指定多种连接类型.例如,我希望我的连接类型是排队的连接和唯一的连接.是否可以在一个语句中指定? QObject::connect(ptrSender,SIGNAL(..),ptrReceiver,SLOT(...),Queued-and-unique) 更新: 按照海报的建议: 我试过使用Qt :: QueuedConnec
我想知道是否可以指定多种连接类型.例如,我希望我的连接类型是排队的连接和唯一的连接.是否可以在一个语句中指定?
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();
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读