Qt注册元类型
来源:互联网 发布:单片机通讯光耦隔离 编辑:程序博客网 时间:2024/05/01 14:08
Registering custom types
February 15th, 2009
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:
QObject::connect: Cannot queue arguments of type 'MyType'
So custom data types have to be registered using qRegisterMetaType()
, like in the example:
qRegisterMetaType<MyType>( "MyType" );
And this example is literal ⇒ when your class is called MyType
, you register it as "MyType"
. Lastly I did something similar to this:
1 2 3
typedef QMap<QString,QImage> MapStringImage;(...)qRegisterMetaType<MapStringImage>( "images" );
I didn’t get the error from QObject::connect
(!), but also didn’t get things working. Wasted few hours hacking QMetaType
class with no effect, and then more by accident than design changed "images"
to "MapStringImage"
and woo-hoo! That was my only problem… That’s why I’m stressing this naming issue, especially that documentation doesn’t tell a lot about it.
BTW I needed to use typedef because otherwise Qt didn’t have a clue what to do with such a complex type.
- Qt注册元类型
- Qt元类型(MetaType)注册门
- Qt注册元类型(MetaType)
- Qt 已注册元对象类型
- 细说Qt 已注册元对象类型
- Qt元类型(MetaType)注册门
- Qt元系统之类型注册
- QT注册自定义类型
- Qt中注册QML类型
- Qt自定义类型的注册与使用
- QT的元类型和QT线程通信的方法
- 实现QT元类型和QT线程通信
- QT的元类型和QT线程通信的方法
- QT的元类型和QT线程通信的方法
- 实现QT元类型和QT线程通信
- QT的元类型和QT线程通信的方法
- 动态属性和元类型的声明和注册
- Qt使用自定义类型信号槽注册问题
- Controller in depth
- 男人不会告诉你的潜规则
- ERP笔记2-善用SVN对系统环境进行配置和组织
- How to configure transparent bridge between SCCP and SIP VoIP systems.
- 社交礼仪笔记(一)
- Qt注册元类型
- 工厂模式(Factory Pattern)
- Objective-C入门教程
- Linux获取进程信息[转]
- Drago Radev's skill list for Ph.D. students
- 什么玩意
- Data Guard学习物理standby高级管理
- 利用XMLHttpRequest对象编写实现Ajax小实例
- 技术人生!