How to register the following data type to enable serialization?

I use QJson to serialize the QObject -derived class. I can serialize the class itself without any problems, but when it comes to one of its members, I have problems.

The class is named CProject and contains the files property, which is defined as:

 QList<CProjectFile> files; 

When serializing an instance of CProject I get a message in the console:

QMetaProperty::read: Unable to handle unregistered datatype 'QList<CProjectFile>' for property 'CProject::files'

I read somewhere that I need to register a data type, so after declaring CProject :

I added the following:
 Q_DECLARE_METATYPE(QList<CProjectFile>) 

... and when I did nothing, I added:

 qRegisterMetaType< QList<CProjectFile> >(); 

Nothing works. What am I doing wrong?

+4
source share
1 answer

I do not know how QJson works, but perhaps this requires flow operators. Try, as shown below, after declaring the CProjectFile class

 class CProjectFile { ... }; Q_DECLARE_METATYPE(CProjectFile) qRegisterMetaType<CProjectFile>("CProjectFile");//Do this if you need signal/slots qRegisterMetaTypeStreamOperators<QList<CProjectFile> >("CProjectFileList"); 

See also QT Doc for stream statements.

+4
source

All Articles