QObject::connect: Cannot queue arguments of type "xxx"的解决方案

版权声明:所有的博客都是个人笔记,交流可以留言。未经允许,谢绝转载。。。 https://blog.csdn.net/qq_35976351/article/details/89949764

问题描述

在跨线程的信号和槽的参数传递中, 参数的类型是自定义的类型, 然而此时出现了错误:

QObject::connect: Cannot queue arguments of type 'Pos'
(Make sure 'Pos' is registered using qRegisterMetaType().)

其中, Pos是自定义的类型:

struct Pos {
    int x, y;
    Pos(int _x = 0, int _y = 0):
        x(_x), y(_y) {}
};

出现问题的类是自定义的Manager, 且该类继承了QThread, 并且是在类的内部进行信号和槽的传递.

解决方案

Manager的头文件中,引入:

#include <QMetaType>

然后在Manager的构造函数最开始的地方添加:

qRegisterMetaType<Pos>("Pos");

重新编译运行即可

猜你喜欢

转载自blog.csdn.net/qq_35976351/article/details/89949764