Object::connect:cannot queue arguments of type ' qmap<qstring,qstring> ' (to use qregistermetatype<stringmap> To register)

Source: Internet
Author: User
Tags sendmsg

Qobject::connect:cannot queue arguments of type ' qmap<qstring,qstring> ', (make sure ' qmap<qstring,qstring> ' is registered using Qregistermetatype ().).

The above error occurs only when cross-thread signaling is passed. Because Qmap is a basic type of QT-aware, it does not require a re-registration in the meta-object system, and there is no problem running in the same thread.

Source:

CPP Code
    1. //  thread class  thread.h   
    2. class thread:PUBLIC&NBSP;QTHREAD&NBSP;&NBSP;
    3. {  
    4.     q_object  
    5.   
    6. PUBLIC:&NBSP;&NBSP;
    7.     thread () {}  
    8.     ~thread () {}  
    9.   
    10. PROTECTED:&NBSP;&NBSP;
    11.     virtual void run ();   
    12.   
    13. signals:  
    14.     void sendmsg (const qmap<qstring,qstring> &msgs) ;   
    15. }  

CPP Code
    1. Signal Reception class Test.h
    2. Test (Thread *th): m_th (TH)
    3. {
    4. //Different threads are connected in queue mode
    5. Connect (m_th,signal (sendmsg (const qmap<qstring,qstring> &)),This,slot (handle (const qmap<  Qstring,qstring> &), qt::queuedconnection);
    6. }

Solution: Register to Metype with the Qregistermetatype () method

CPP Code
    1. Thread.h
    2. typedef qmap<qstring,qstring> STRINGMAP; the//typedef operator is an alias for Qmap
    3. void sendmsg (const STRINGMAP &);

CPP Code
    1. Test.h
    2. Test (Thread *th): m_th (TH)
    3. {
    4. //Register Qmap to meta-object system
    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> ' (to use Qregistermetatype<stringmap > Registration)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.