Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Showcase
  4. Qt Property Generator
Qt 6.11 is out! See what's new in the release blog

Qt Property Generator

Scheduled Pinned Locked Moved Showcase
15 Posts 3 Posters 9.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    andre
    wrote on last edited by
    #5

    I'd ask around at #qt-creator on IRC (freenode network) for that.

    1 Reply Last reply
    0
    • U Offline
      U Offline
      utcenter
      wrote on last edited by
      #6

      OK, fixed a few things:

      • getter is no longer slot

      • getter is const

      • setter checks if the value is different

      @// Auto generated property dateOfBirth : QDate
      Q_PROPERTY(QDate dateOfBirth READ dateOfBirth WRITE setDateOfBirth RESET resetDateOfBirth NOTIFY dateOfBirthChanged)
      private: QDate m_dateOfBirth;

      public: inline QDate dateOfBirth() const {
      return m_dateOfBirth;
      }
      Q_SLOT Person &setDateOfBirth(const QDate &v) {
      if (m_dateOfBirth != v) {
      m_dateOfBirth = v;
      emit dateOfBirthChanged(m_dateOfBirth);
      }
      return *this;
      }
      Q_SLOT inline void resetDateOfBirth() {
      // TODO reset
      }
      Q_SIGNAL void dateOfBirthChanged(QDate);@

      1 Reply Last reply
      0
      • sierdzioS Offline
        sierdzioS Offline
        sierdzio
        Moderators
        wrote on last edited by
        #7

        Shouldn't the getter be at least a Q_INVOKABLE?

        (Z(:^

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #8

          [quote author="sierdzio" date="1360670794"]Shouldn't the getter be at least a Q_INVOKABLE?[/quote]

          Why would it need to?

          1 Reply Last reply
          0
          • U Offline
            U Offline
            utcenter
            wrote on last edited by
            #9

            It would make sense to be Q_INVOKABLE if it wasn't a property to begin with, you know... to use in QML and in the designer. But it is a property so this is taken care of.

            1 Reply Last reply
            0
            • sierdzioS Offline
              sierdzioS Offline
              sierdzio
              Moderators
              wrote on last edited by
              #10

              OK. Guess I've always been adding it without actually testing if it's required ;)

              (Z(:^

              1 Reply Last reply
              0
              • U Offline
                U Offline
                utcenter
                wrote on last edited by
                #11

                I improved the tool by adding some functionality:

                • now it can generate an arbitrary number of properties at the same time

                • it is possible to chose between inline definitions in the header or only declarations in the header and definitions in the cpp

                • properties can be grouped - the generated source is packed for each property, or non-grouped and the code is not packed for each property but for each property component

                I also added a link for a pre-build executable for windows in the first post.

                It is still all pretty crude, but in this form the tool is considerably more useful and can generate a considerable amount of code with just a few mouse clicks, thus saving considerable time as well.

                !http://i45.tinypic.com/105tzzo.png(p1)!
                !http://i45.tinypic.com/6z7jgo.png(p2)!
                !http://i46.tinypic.com/16gh6rd.png(p3)!

                1 Reply Last reply
                0
                • U Offline
                  U Offline
                  utcenter
                  wrote on last edited by
                  #12

                  And the resulting code:

                  inline non-grouped:
                  @//Auto-generated properties:
                  Q_PROPERTY(int number READ number WRITE setNumber RESET resetNumber NOTIFY numberChanged REVISION 1)
                  Q_PROPERTY(QColor color READ color WRITE setColor RESET resetColor NOTIFY colorChanged)
                  Q_PROPERTY(QSize size READ size WRITE setSize RESET resetSize NOTIFY sizeChanged)
                  Q_PROPERTY(uint id READ id CONSTANT)
                  Q_PROPERTY(QString name READ name WRITE setName RESET resetName NOTIFY nameChanged)
                  Q_PROPERTY(qreal real READ real WRITE setReal RESET resetReal NOTIFY realChanged DESIGNABLE false SCRIPTABLE false)

                  private:
                  int m_number;
                  QColor m_color;
                  QSize m_size;
                  uint m_id;
                  QString m_name;
                  qreal m_real;

                  public:
                  inline int number() const {
                  return m_number;
                  }

                  inline QColor color() const {
                  return m_color;
                  }

                  inline QSize size() const {
                  return m_size;
                  }

                  inline uint id() const {
                  return m_id;
                  }

                  inline QString name() const {
                  return m_name;
                  }

                  inline qreal real() const {
                  return m_real;
                  }

                  Q_SLOT TestClass &setNumber(const int &v) {
                  if (m_number != v) {
                  m_number = v;
                  emit numberChanged(m_number);
                  }
                  return *this;
                  }

                  Q_SLOT TestClass &setColor(const QColor &v) {
                  if (m_color != v) {
                  m_color = v;
                  emit colorChanged(m_color);
                  }
                  return *this;
                  }

                  Q_SLOT TestClass &setSize(const QSize &v) {
                  if (m_size != v) {
                  m_size = v;
                  emit sizeChanged(m_size);
                  }
                  return *this;
                  }

                  Q_SLOT TestClass &setName(const QString &v) {
                  if (m_name != v) {
                  m_name = v;
                  emit nameChanged(m_name);
                  }
                  return *this;
                  }

                  Q_SLOT TestClass &setReal(const qreal &v) {
                  if (m_real != v) {
                  m_real = v;
                  emit realChanged(m_real);
                  }
                  return *this;
                  }

                  Q_SLOT void resetNumber() {
                  //TODO reset
                  }

                  Q_SLOT void resetColor() {
                  //TODO reset
                  }

                  Q_SLOT void resetSize() {
                  //TODO reset
                  }

                  Q_SLOT void resetName() {
                  //TODO reset
                  }

                  Q_SLOT void resetReal() {
                  //TODO reset
                  }

                  Q_SIGNAL void numberChanged(int);
                  Q_SIGNAL void colorChanged(QColor &);
                  Q_SIGNAL void sizeChanged(QSize &);
                  Q_SIGNAL void nameChanged(QString &);
                  Q_SIGNAL void realChanged(qreal);
                  @

                  inline grouped:
                  @
                  //Auto-generated property number : int
                  Q_PROPERTY(int number READ number WRITE setNumber RESET resetNumber NOTIFY numberChanged REVISION 1)
                  private: int m_number;
                  public: inline int number() const {
                  return m_number;
                  }

                  Q_SLOT TestClass &setNumber(const int &v) {
                  if (m_number != v) {
                  m_number = v;
                  emit numberChanged(m_number);
                  }
                  return *this;
                  }

                  Q_SLOT void resetNumber() {
                  //TODO reset
                  }

                  Q_SIGNAL void numberChanged(int);

                  //Auto-generated property color : QColor
                  Q_PROPERTY(QColor color READ color WRITE setColor RESET resetColor NOTIFY colorChanged)
                  private: QColor m_color;
                  public: inline QColor color() const {
                  return m_color;
                  }

                  Q_SLOT TestClass &setColor(const QColor &v) {
                  if (m_color != v) {
                  m_color = v;
                  emit colorChanged(m_color);
                  }
                  return *this;
                  }

                  Q_SLOT void resetColor() {
                  //TODO reset
                  }

                  Q_SIGNAL void colorChanged(QColor &);

                  //Auto-generated property size : QSize
                  Q_PROPERTY(QSize size READ size WRITE setSize RESET resetSize NOTIFY sizeChanged)
                  private: QSize m_size;
                  public: inline QSize size() const {
                  return m_size;
                  }

                  Q_SLOT TestClass &setSize(const QSize &v) {
                  if (m_size != v) {
                  m_size = v;
                  emit sizeChanged(m_size);
                  }
                  return *this;
                  }

                  Q_SLOT void resetSize() {
                  //TODO reset
                  }

                  Q_SIGNAL void sizeChanged(QSize &);

                  //Auto-generated property id : uint
                  Q_PROPERTY(uint id READ id CONSTANT)
                  private: uint m_id;
                  public: inline uint id() const {
                  return m_id;
                  }

                  //Auto-generated property name : QString
                  Q_PROPERTY(QString name READ name WRITE setName RESET resetName NOTIFY nameChanged)
                  private: QString m_name;
                  public: inline QString name() const {
                  return m_name;
                  }

                  Q_SLOT TestClass &setName(const QString &v) {
                  if (m_name != v) {
                  m_name = v;
                  emit nameChanged(m_name);
                  }
                  return *this;
                  }

                  Q_SLOT void resetName() {
                  //TODO reset
                  }

                  Q_SIGNAL void nameChanged(QString &);

                  //Auto-generated property real : qreal
                  Q_PROPERTY(qreal real READ real WRITE setReal RESET resetReal NOTIFY realChanged DESIGNABLE false SCRIPTABLE false)
                  private: qreal m_real;
                  public: inline qreal real() const {
                  return m_real;
                  }

                  Q_SLOT TestClass &setReal(const qreal &v) {
                  if (m_real != v) {
                  m_real = v;
                  emit realChanged(m_real);
                  }
                  return *this;
                  }

                  Q_SLOT void resetReal() {
                  //TODO reset
                  }

                  Q_SIGNAL void realChanged(qreal);

                  @

                  1 Reply Last reply
                  0
                  • U Offline
                    U Offline
                    utcenter
                    wrote on last edited by
                    #13

                    non-inline non-grouped:
                    @// header
                    //Auto-generated properties:
                    Q_PROPERTY(int number READ number WRITE setNumber RESET resetNumber NOTIFY numberChanged REVISION 1)
                    Q_PROPERTY(QColor color READ color WRITE setColor RESET resetColor NOTIFY colorChanged)
                    Q_PROPERTY(QSize size READ size WRITE setSize RESET resetSize NOTIFY sizeChanged)
                    Q_PROPERTY(uint id READ id CONSTANT)
                    Q_PROPERTY(QString name READ name WRITE setName RESET resetName NOTIFY nameChanged)
                    Q_PROPERTY(qreal real READ real WRITE setReal RESET resetReal NOTIFY realChanged DESIGNABLE false SCRIPTABLE false)

                    private:
                    int m_number;
                    QColor m_color;
                    QSize m_size;
                    uint m_id;
                    QString m_name;
                    qreal m_real;

                    public:
                    int number() const;
                    QColor color() const;
                    QSize size() const;
                    uint id() const;
                    QString name() const;
                    qreal real() const;

                    Q_SLOT TestClass &setNumber(const int &v);
                    Q_SLOT TestClass &setColor(const QColor &v);
                    Q_SLOT TestClass &setSize(const QSize &v);
                    Q_SLOT TestClass &setName(const QString &v);
                    Q_SLOT TestClass &setReal(const qreal &v);

                    Q_SLOT void resetNumber();
                    Q_SLOT void resetColor();
                    Q_SLOT void resetSize();
                    Q_SLOT void resetName();
                    Q_SLOT void resetReal();

                    Q_SIGNAL void numberChanged(int);
                    Q_SIGNAL void colorChanged(QColor &);
                    Q_SIGNAL void sizeChanged(QSize &);
                    Q_SIGNAL void nameChanged(QString &);
                    Q_SIGNAL void realChanged(qreal);

                    // source
                    int TestClass::number() const {
                    return m_number;
                    }

                    QColor TestClass::color() const {
                    return m_color;
                    }

                    QSize TestClass::size() const {
                    return m_size;
                    }

                    uint TestClass::id() const {
                    return m_id;
                    }

                    QString TestClass::name() const {
                    return m_name;
                    }

                    qreal TestClass::real() const {
                    return m_real;
                    }

                    TestClass &TestClass::setNumber(const int &v) {
                    if (m_number != v) {
                    m_number = v;
                    emit numberChanged(m_number);
                    }
                    return *this;
                    }

                    TestClass &TestClass::setColor(const QColor &v) {
                    if (m_color != v) {
                    m_color = v;
                    emit colorChanged(m_color);
                    }
                    return *this;
                    }

                    TestClass &TestClass::setSize(const QSize &v) {
                    if (m_size != v) {
                    m_size = v;
                    emit sizeChanged(m_size);
                    }
                    return *this;
                    }

                    TestClass &TestClass::setName(const QString &v) {
                    if (m_name != v) {
                    m_name = v;
                    emit nameChanged(m_name);
                    }
                    return *this;
                    }

                    TestClass &TestClass::setReal(const qreal &v) {
                    if (m_real != v) {
                    m_real = v;
                    emit realChanged(m_real);
                    }
                    return *this;
                    }

                    int TestClass::resetNumber() {
                    //TODO reset
                    }

                    QColor TestClass::resetColor() {
                    //TODO reset
                    }

                    QSize TestClass::resetSize() {
                    //TODO reset
                    }

                    QString TestClass::resetName() {
                    //TODO reset
                    }

                    qreal TestClass::resetReal() {
                    //TODO reset
                    }
                    @

                    non-inline grouped:
                    @//header
                    //Auto-generated property number : int
                    Q_PROPERTY(int number READ number WRITE setNumber RESET resetNumber NOTIFY numberChanged REVISION 1)
                    private: int m_number;
                    public: int number() const;
                    Q_SLOT TestClass &setNumber(const int &v);
                    Q_SLOT void resetNumber();
                    Q_SIGNAL void numberChanged(int);

                    //Auto-generated property color : QColor
                    Q_PROPERTY(QColor color READ color WRITE setColor RESET resetColor NOTIFY colorChanged)
                    private: QColor m_color;
                    public: QColor color() const;
                    Q_SLOT TestClass &setColor(const QColor &v);
                    Q_SLOT void resetColor();
                    Q_SIGNAL void colorChanged(QColor &);

                    //Auto-generated property size : QSize
                    Q_PROPERTY(QSize size READ size WRITE setSize RESET resetSize NOTIFY sizeChanged)
                    private: QSize m_size;
                    public: QSize size() const;
                    Q_SLOT TestClass &setSize(const QSize &v);
                    Q_SLOT void resetSize();
                    Q_SIGNAL void sizeChanged(QSize &);

                    //Auto-generated property id : uint
                    Q_PROPERTY(uint id READ id CONSTANT)
                    private: uint m_id;
                    public: uint id() const;

                    //Auto-generated property name : QString
                    Q_PROPERTY(QString name READ name WRITE setName RESET resetName NOTIFY nameChanged)
                    private: QString m_name;
                    public: QString name() const;
                    Q_SLOT TestClass &setName(const QString &v);
                    Q_SLOT void resetName();
                    Q_SIGNAL void nameChanged(QString &);

                    //Auto-generated property real : qreal
                    Q_PROPERTY(qreal real READ real WRITE setReal RESET resetReal NOTIFY realChanged DESIGNABLE false SCRIPTABLE false)
                    private: qreal m_real;
                    public: qreal real() const;
                    Q_SLOT TestClass &setReal(const qreal &v);
                    Q_SLOT void resetReal();
                    Q_SIGNAL void realChanged(qreal);

                    // source
                    int TestClass::number() const {
                    return m_number;
                    }

                    TestClass &TestClass::setNumber(const int &v) {
                    if (m_number != v) {
                    m_number = v;
                    emit numberChanged(m_number);
                    }
                    return *this;
                    }

                    int TestClass::resetNumber() {
                    //TODO reset
                    }

                    QColor TestClass::color() const {
                    return m_color;
                    }

                    TestClass &TestClass::setColor(const QColor &v) {
                    if (m_color != v) {
                    m_color = v;
                    emit colorChanged(m_color);
                    }
                    return *this;
                    }

                    QColor TestClass::resetColor() {
                    //TODO reset
                    }

                    QSize TestClass::size() const {
                    return m_size;
                    }

                    TestClass &TestClass::setSize(const QSize &v) {
                    if (m_size != v) {
                    m_size = v;
                    emit sizeChanged(m_size);
                    }
                    return *this;
                    }

                    QSize TestClass::resetSize() {
                    //TODO reset
                    }

                    uint TestClass::id() const {
                    return m_id;
                    }

                    QString TestClass::name() const {
                    return m_name;
                    }

                    TestClass &TestClass::setName(const QString &v) {
                    if (m_name != v) {
                    m_name = v;
                    emit nameChanged(m_name);
                    }
                    return *this;
                    }

                    QString TestClass::resetName() {
                    //TODO reset
                    }

                    qreal TestClass::real() const {
                    return m_real;
                    }

                    TestClass &TestClass::setReal(const qreal &v) {
                    if (m_real != v) {
                    m_real = v;
                    emit realChanged(m_real);
                    }
                    return *this;
                    }

                    qreal TestClass::resetReal() {
                    //TODO reset
                    }

                    @

                    1 Reply Last reply
                    0
                    • U Offline
                      U Offline
                      utcenter
                      wrote on last edited by
                      #14

                      Removed a few bugs I discovered while using the generator.

                      Also found this in the doc:

                      bq. The READ function is const and returns the property type. The WRITE function returns void and has exactly one parameter of the property type. The meta-object compiler enforces these requirements.

                      which got me thinking chaining won't work, but after a quick test it does seem to work properly.

                      1 Reply Last reply
                      0
                      • U Offline
                        U Offline
                        utcenter
                        wrote on last edited by
                        #15

                        Minor fixes:

                        • no private member is generated for non-STORED properties

                        • WRITE and NOTIFY is disabled for CONSTANT properties

                        1 Reply Last reply
                        0

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved