8

クラスがあり、それを Qvariant で使用したいので、メタ型を宣言して登録する必要があります。これは私がやったことです:

class blabla: public QThread
{
   Q_OBJECT
 .
 .
 .
 };
 Q_DECLARE_METATYPE(blabla)

しかし、このコードは私にエラーを与えています:

In copy constructor ‘QThread::QThread(const QThread&)’:
instantiated from ‘void* qMetaTypeConstructHelper(const T*) [with T = blabla]’
instantiated from ‘int qRegisterMetaType(const char*, T*) [with T = blabla]’
instantiated from here
‘QObject::QObject(const QObject&)’ is private
 within this context
In file included from UnitTest.cpp:16:0:
blabla.h: In copy constructor ‘blabla::blabla(const blabla&)’:
note: synthesized method ‘QThread::QThread(const QThread&)’ first required here 
In file included from /usr/include/QtCore/qvariant.h:48:0,
             from /usr/include/QtCore/qabstractitemmodel.h:45,
             from /usr/include/QtCore/QtCore:7,
             from /usr/include/QtTest/QtTest:3,
             from UnitTest.h:16,
             from UnitTest.cpp:14:
In function ‘void* qMetaTypeConstructHelper(const T*) [with T = blabla]’:
note: synthesized method ‘blabla::blabla(const blabla&)’ first required here 
make[1]: *** [build/obj/UnitTest.o] Error 1

met-type を登録する必要があると思いますが、どこにqRegisterMetaType<MyClass>("MyClass");. メタ型宣言マクロの後につけてみたのですが、エラーになりました。私を正しい道に導くコメントやヒントを感謝します。

4

1 に答える 1

20

オブジェクトは に配置するとコピーされますQVariantが、QObject派生クラスはコピーできないため、解決策はクラスへのポインターを使用することです。

Q_DECLARE_METATYPE( blabla* )

またqRegisterMetaType<T>()、キューに入れられたシグナル/スロット接続を介してオブジェクトを送信する場合にのみ必要です。

于 2013-01-08T14:17:21.793 に答える