Hi, I'm trying to serialize a pimpl object, but get a compilation error. I prepared a minimal example:

record_p.h
Qt Code:
  1. #include "record.h"
  2.  
  3. namespace MyApp {
  4.  
  5. class RecordPrivate : public QObject
  6. {
  7. Q_OBJECT
  8.  
  9. public:
  10. RecordPrivate ( Record* qq, QObject* parent = 0 );
  11.  
  12. QString name() const;
  13. uint age() const;
  14.  
  15. private:
  16. Record* const q;
  17.  
  18. QString m_name;
  19. uint m_age;
  20. };
  21.  
  22. }
To copy to clipboard, switch view to plain text mode 

record.h
Qt Code:
  1. namespace MyApp {
  2.  
  3. class RecordPrivate;
  4.  
  5. class Record : public QObject
  6. {
  7. Q_OBJECT
  8. Q_PROPERTY( QString name READ name CONSTANT )
  9. Q_PROPERTY( uint age READ age CONSTANT )
  10.  
  11. public:
  12. explicit Record(QObject *parent = 0);
  13. virtual ~Record();
  14.  
  15. QString name() const;
  16. uint age() const;
  17.  
  18. private:
  19. Q_DISABLE_COPY( Record )
  20. RecordPrivate* const d;
  21. friend class RecordPrivate;
  22.  
  23. };
  24.  
  25. typedef QSharedPointer<Record> RecordPtr;
  26.  
  27. }
  28.  
  29. QDataStream& operator<<( QDataStream& dataStream, const MyApp::RecordPtr record );
  30.  
  31. Q_DECLARE_METATYPE( MyApp::RecordPtr )
To copy to clipboard, switch view to plain text mode 

record.cpp
Qt Code:
  1. #include "record_p.h"
  2.  
  3. using namespace MyApp;
  4.  
  5. RecordPrivate::RecordPrivate ( Record* qq, QObject* parent ) :
  6. QObject ( parent ),
  7. q ( qq )
  8. {
  9. }
  10.  
  11. uint RecordPrivate::age() const
  12. {
  13. return m_age;
  14. }
  15.  
  16. QString RecordPrivate::name() const
  17. {
  18. return m_name;
  19. }
  20.  
  21. Record::Record(QObject *parent) :
  22. QObject(parent),
  23. d ( new RecordPrivate ( this ) )
  24. {
  25. }
  26.  
  27. Record::~Record()
  28. {
  29. delete d;
  30. }
  31.  
  32. uint Record::age() const
  33. {
  34. return d->age();
  35. }
  36.  
  37. QString Record::name() const
  38. {
  39. return d->name();
  40. }
  41.  
  42. QDataStream& operator<<( QDataStream& dataStream, const RecordPtr record )
  43. {
  44. for(int i=0; i< record->metaObject()->propertyCount(); ++i) {
  45. if(record->metaObject()->property(i).isStored(record)) {
  46. dataStream << record->metaObject()->property(i).read(record);
  47. }
  48. }
  49. return dataStream;
  50. }
To copy to clipboard, switch view to plain text mode 

record.cpp:-1: In function 'QDataStream& operator<<(QDataStream&, MyApp::RecordPtr)':
no matching function for call to 'QMetaProperty::isStored(const RecordPtr&)'
if(record->metaObject()->property(i).isStored(record)) {
^
candidate is:
bool QMetaProperty::isStored(const QObject*) const
bool isStored(const QObject *obj = 0) const;
^
note: no known conversion for argument 1 from 'const RecordPtr {aka const QSharedPointer<MyApp::Record>}' to 'const QObject*'
Where is my error?

Very thanks.