1

Can a user-made subclass of Parent of QObject have multiple Q_PROPERTYs of the same name (possibly with different types)? What if I subclass Parent to Child, and give that a similarly-named Q_PROPERTY? Like so:

#include <QObject>

class Parent : public QObject {
  Q_OBJECT

  Q_PROPERTY(int something MEMBER m_something)
  Q_PROPERTY(double something MEMBER m_somethingElse)
  Q_PROPERTY(QString third MEMBER m_third)

  int m_something;
  double m_somethingElse;
  QString m_third;
};

class Child : public Parent {
  Q_OBJECT

  Q_PROPERTY(QString third MEMBER m_fourth)

  QString m_fourth;
};
JesseTG
  • 2,025
  • 1
  • 24
  • 48
  • well, have you tried compiling? – dtech Mar 25 '16 at 23:33
  • Yes, actually, I have. And while it works...should it? It wouldn't be the first time I thought I'd discovered some neat undocumented feature that turned out to be an implementation detail (and thus not useful in later versions). – JesseTG Mar 25 '16 at 23:45
  • I don't know how it is implemented internally, but as far as the automatically generated accessory are concerned, those are regular functions, so they can be overriden. However, having the same name for multiple properties might prove to be problematic for the functionality that involves the meta system, where property lookup is by name. – dtech Mar 25 '16 at 23:54
  • As ddriver said, this might compile, but will fail as soon as you actually make use of the property by looking it up from e.g. QML – Frank Osterfeld Mar 27 '16 at 06:57
  • Seems like `moc` should enforce that kind of thing, then. – JesseTG Mar 27 '16 at 18:05

0 Answers0