Qt信号槽传递非QObject类型对象的参数

关于在Qt中信号槽传递QObject类型的参数的方法:

1.第一种注册法:qRegisterMetatType<MoSystemLog>("MoSystemLog")

2. 第二种修改Connect,加一个属性Qt::directConnection.

connect(cm, SIGNAL(sendLog(QUuid, QByteArray, bool)),this,SLOT(sendRes(QUuid,QByteArray,bool)), Qt::DirectConnection);

第二种方法有风险

 

1、第一种解决方法,即使用排队方式的信号-槽机制,Qt的元对象系统(meta-object system)必须知道信号传递的参数类型。这样元系统可以将信号参数COPY下来,放在队列中等待事件唤醒,供槽函数调用。Just a note here, if you would have to pass custom data types between threads in Qt. As we know, a signal-slot connection is then (by default) of type Qt::QueuedConnection. Because in such a situation Qt needs to store passed parameters for a while, it creates their temporary copies. If it doesn’t recognize the passed data type, throws out an error:

2、第二种方法,直接调用对方槽函数,不需要保存参数。但是官方认为这样做有风险。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值