分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 前端开发

Object::connect: Cannot queue arguments of type 'QMap<QString,QString>'(要使用qRegisterMetaType<StringMap>进行注册)

发布时间:2023-09-06 02:13责任编辑:白小东关键词:暂无标签

   QObject::connect: Cannot queue arguments of type ‘QMap<QString,QString>‘,(Make sure ‘QMap<QString,QString>‘ is registered using qRegisterMetaType().).  

   上述错误,只有在跨线程信号传递时才会出现.  因为QMap是QT可识别的基本类型,不需要再注册元对象系统中,在同一个线程中运行没有问题.

   源码: 

Cpp代码  
  1. // 线程类 thread.h   
  2. class Thread:public QThread  
  3. {  
  4.     Q_OBJECT  
  5.   
  6. public:  
  7.     Thread(){}  
  8.     ~Thread(){}  
  9.   
  10. protected:  
  11.     virtual void run();  
  12.   
  13. signals:  
  14.     void sendMsg(const QMap<QString,QString> &msgs);  
  15. }  

  

Cpp代码  
  1. // 信号接收类 test.h  
  2. Test(Thread *th):m_th(th)  
  3. {  
  4.   // 不同线程用队列方式连接  
  5.   connect(m_th,SIGNAL(sendMsg(const QMap<QString,QString> &)),this,SLOT(handle(const QMap<QString,QString> &)),Qt::QueuedConnection);  
  6. }  

    解决方案:通过qRegisterMetaType()方法注册至Metype中

Cpp代码  
  1. // thread.h  
  2. typedef QMap<QString,QString> StringMap; // typedef操作符为QMap起一别名  
  3.   
  4. void sendMsg(const StringMap &);  
Cpp代码  
  1. // test.h   
  2. Test(Thread *th):m_th(th)  
  3. {  
  4.     // 注册QMap至元对象系统  
  5.     qRegisterMetaType<StringMap>("StringMap");  
  6.     connect(m_th,SIGNAL(sendMsg(const StringMap &)),this,SLOT(handle(const StringMap &)),Qt::QueuedConnection);  
  7. }  

     

 
 
http://tcspecial.iteye.com/blog/1897006

Object::connect: Cannot queue arguments of type 'QMap<QString,QString>'(要使用qRegisterMetaType<StringMap>进行注册)

原文地址:https://www.cnblogs.com/findumars/p/9589328.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved