QObject::connect: Cannot queue arguments of type

问题:

Hi!

I have a small problem concerning two threads and signals/slots connected between them.

My connect looks like this.

  1. ...
  2. qRegisterMetaType < QVector < QVector < int >  >  > ( "MyArray" ) ;
  3. ...
  4. connect (sender , SIGNAL (dataChanged ( QVector < QVector < int >  > ) ) ,receiver , SLOT (hasDataChanged ( QVector < QVector < int >  > ) ) ) ;

If the signal is being emitted, I get this error:

  1. QObject :: connect : Cannot queue arguments of type 'QVector >'
  2. (Make sure  'QVector >' is registered  usingqRegisterMetaType ( ). )

Also note that I have my sig/slots with a reference, but if I used a connect like this:

  1. connect (sender , SIGNAL (dataChanged ( QVector < QVector < int >  >& ) ) ,receiver , SLOT (hasDataChanged ( QVector < QVector < int >  >& ) ) ) ;

I’m getting this:
Object::connect: No such signal dataChanged(QVector >&)

Sender

  1. signals :
  2.     void dataChanged ( const  QVector < QVector < int >  >  &data ) ;

Receiver

  1. public  slots :
  2.      void hasDataChanged ( const  QVector < QVector < int >  >  &data ) ;

How can I achieve a connection, do I need to put Q_DECLARE_METATYPE somewhere?

Thanks for your help!

解决方法:

  1. typedef  QVector < QVector < int >  > MyArray ;
  2. // ...
  3. qRegisterMetaType <MyArray > ( "MyArray" ) ;
  4. // ...
  5. connect (
  6.      this , SIGNAL (blurbDone2 (MyArray ) ) ,
  7.      this , SLOT (slotBlurb2 (MyArray ) ) ,
  8.      Qt :: QueuedConnection ) ;
  9.  
  10. // with this signatures:
  11. signals :
  12.      void blurbDone2 ( const MyArray  &bb ) ;
  13.  
  14. protected  slots :
  15.      void slotBlurb2 ( const MyArray  &bb ) ;


转自:http://qt-project.org/forums/viewthread/2884

你可能感兴趣的:(Qt开发)