查看文章
 
解决Qt信号与槽的一个问题:QObject::connect: Cannot queue arguments of type 'QUuid'
2009-07-03 2:14

程序能编译运行,但出现这个提示:
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.

Constant Value Description
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'

call qRegisterMetaType() 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


类别:qt编程||添加到搜藏 |分享到i贴吧|浏览(4925)|评论 (0)
 
 
最近读者:
 
网友评论:
发表评论:
姓 名:
网址或邮箱: (选填)
内 容:
     

   
帮助中心 | 空间客服 | 投诉中心 | 空间协议
©2012 Baidu