zoukankan      html  css  js  c++  java
  • Object::connect: Cannot queue arguments of type 'QMap<QString,QString>'(要使用qRegisterMetaType<StringMap>进行注册)

       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
  • 相关阅读:
    统计nginx日志里访问次数最多的前十个IP
    while 格式化输出 运算符 字符编码
    Python 软件安装
    Python 基础
    Typora 基础的使用方法
    Django ORM (四) annotate,F,Q 查询
    Django 惰性机制
    Django ORM (三) 查询,删除,更新操作
    Django ORM (二) 增加操作
    Django ORM (一) 创建数据库和模型常用的字段类型参数及Field 重要参数介绍
  • 原文地址:https://www.cnblogs.com/findumars/p/9589328.html
Copyright © 2011-2022 走看看