Qt 注册自定义类型

注册自定义类型

信号和槽在不同线程中传自定义参数时,需要注册。否则就会报错:
QObject::connect: Cannot queue arguments of type ‘QVector’
(Make sure ‘QVector’ is registered using qRegisterMetaType().)

注册格式:

qRegisterMetaType<MyClass>("MyClass");

例如:

#include "widget.h"
#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    qRegisterMetaType<QVector<int>>("QVector<int>");
    Widget w;
    w.show();
    return a.exec();
}

源码: https://github.com/sunlianqi/qt/tree/master/registerMetaType.

猜你喜欢

转载自blog.csdn.net/sinat_33859977/article/details/114631349
今日推荐