Qt使用自定义类型信号槽注册问题

1、报错:

 QObject::connect: Cannot queue arguments of type 'QList<myData>'
(Make sure 'QList<myData>' is registered using qRegisterMetaType().)


2、使用:

 void updateDrawData(QList<myData>);
    emit updateDrawData(m_myData);

 QList里面不能是自己定义的数据类型吗,像类对象或者结构体?

3、注册:


  1. Q_DECLARE_METATYPE(MyNamespace::MyData) // registers the type with "MyNamespace::MyData" name
  2.  
  3. qRegisterMetaType<MyNamespace::MyData>("MyData") // registers the same type with "MyData" name



推荐论坛文章:


As I understand here I have type names conflict:

Qt Code:
  1. Q_DECLARE_METATYPE(MyNamespace::MyData) // registers the type with "MyNamespace::MyData" name
  2.  
  3. qRegisterMetaType<MyNamespace::MyData>("MyData") // registers the same type with "MyData" name
To copy to clipboard, switch view to plain text mode 

The signal I have expects the type to be registered with "MyData" name. So if I change declaration of the signal to be: 

Qt Code:
  1. namespace MyNamespace
  2. {
  3.  
  4. class MyClass : public QObject
  5. {
  6. Q_OBJECT
  7.  
  8. public:
  9. ...
  10. signals:
  11. void mySignal(const MyNamespace::MyData &);
  12. };
  13. }
To copy to clipboard, switch view to plain text mode 


Then everything starts working.

The question now is, why do I have to fully qualify the class in the signal declaration ? The class declaration (where the signal is declared) is located in the same namespace. 

Could someone please explain me the full logic covered behind this ?
阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页