织梦CMS - 轻松建站从此开始!

罗索

解决Qt信号与槽的一个问题:QObject::connect: Cannot queue arg

jackyhwei 发布于 2011-10-11 13:07 点击:次 
程序能编译运行,但出现这个提示:QObject::connect: Cannot queue arguments of type 'QUuid'(Make sure 'QUuid' is registed using qRegisterMetaType().)
TAG:

程序能编译运行,但出现这个提示:
QObject::connect: Cannot queue arguments of type 'QUuid'
(Make sure 'QUuid' is registed using qRegisterMetaType().)

意思是说,信号槽队列中的数据类型必须是系统能识别的元类型,不然得用qRegisterMetaType()进行注册。

参考如下链接和Qt的帮助文档即可解决这个问题:
http://blog.ayoy.net/2009/2/15/registering-custom-types

http://www.qtcentre.org/forum/f-qt-programming-2/t-qobjectconnect-cannot-queue-arguments-of-type-qmodelindex-8926.html

enum Qt::ConnectionType

This enum describes the types of connection that can be used between signals and slots. In particular, it determines whether a particular signal is delivered to a slot immediately or queued for delivery at a later time.

     
Qt::DirectConnection 1 When emitted, the signal is immediately delivered to the slot.
Qt::QueuedConnection 2 When emitted, the signal is queued until the event loop is able to deliver it to the slot.
Qt::BlockingQueuedConnection 4 Same as QueuedConnection, except that the current thread blocks until the slot has been delivered. This connection type should only be used for receivers in a different thread. Note that misuse of this type can lead to deadlocks in your application.
Qt::AutoConnection 0 If the signal is emitted from the thread in which the receiving object lives, the slot is invoked directly, as with Qt::DirectConnection; otherwise the signal is queued, as with Qt::QueuedConnection.

With queued connections, the parameters must be of types that are known to Qt's meta-object system, because Qt needs to copy the arguments to store them in an event behind the scenes. If you try to use a queued connection and get the error message

QObject::connect: Cannot queue arguments of type 'MyType'

callqRegisterMetaType() to register the data type before you establish the connection.


注意上面紫色的内容。

connect的第五个参数用于指定反应速度:

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

可解决因信号没有及时发送,致使connect的接收方的槽不能作进一步处理,如上表中绿色部分内容所述。

另附:
QT的信号与槽机制介绍:http://www.3800hk.com/Article/os/Linux/bckflu/2005-08-06/Article_44236.html

 

(zorru)
本站文章除注明转载外,均为本站原创或编译欢迎任何形式的转载,但请务必注明出处,尊重他人劳动,同学习共成长。转载请注明:文章转载自:罗索实验室 [http://www.rosoo.net/a/201110/15118.html]
本文出处:hi.baidu.com/zorru 作者:zorru
顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 验证码:点击我更换图片
栏目列表
将本文分享到微信
织梦二维码生成器
推荐内容