I'm trying to develop a class that will be used in a reflection driven application and I ran into an interesting issue that I'm hoping there is a solution to. Let's say I have a class Dummy that has a few properties, one of which is a pointer to another Dummy object:
Qt Code:
  1. class Dummy : public QObject
  2. {
  3. Q_OBJECT
  4. Q_PROPERTY(int id READ id WRITE setId)
  5. Q_PROPERTY(QObject * child READ child)
  6.  
  7. int myId;
  8. DummyObject *myChild;
  9.  
  10. public:
  11.  
  12. Dummy(int id)
  13. : myId(id), myChild(0)
  14. {
  15. if (myId == 0)
  16. {
  17. myChild = new Dummy(myId + 1);
  18. }
  19. }
  20.  
  21. ~Dummy()
  22. {
  23. delete myChild;
  24. }
  25.  
  26. int id() const
  27. {
  28. return myId;
  29. }
  30.  
  31. void setId(int id)
  32. {
  33. myId = id;
  34. }
  35.  
  36. QObject * child()
  37. {
  38. return myChild;
  39. }
  40.  
  41. };
To copy to clipboard, switch view to plain text mode 

And then lets say I create a new Dummy object with id = 0 (so it has one child with id = 1), if I pass the parent Dummy object to a function that takes a constant reference to a QObject (or a constant pointer for that matter), how can I guarantee const-correctness on the child function? I tried the obvious: Q_PROPERTY(const QObject * child READ child) and then making const QObject * child() const (which is really how I want this function to look like), but then the moc complains about: "Unable to handle unregistered datatype 'const QObject*'". I just can't figure out how to make it so that if I pass a constant reference or pointer to a Dummy object that the "child" function (through the qt property system) will expose a constant reference or pointer (to ensure const-correctness).