原创 收藏QT开发相关问题

2011-10-19 17:34 1118 1 1 分类: 软件与OS
解决Qt信号与槽的一个问题:QObject::connect: Cannot queue arguments of type 'QUuid'
2009-07-03 02: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

PARTNER CONTENT

文章评论0条评论)

登录后参与讨论
我要评论
0
1
关闭 站长推荐上一条 /3 下一条