注册自定义类型
信号和槽在不同线程中传自定义参数时,需要注册。否则就会报错:
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.