[Development] The future of QProperty and QBindable

Ulf Hermann ulf.hermann at qt.io
Mon Mar 24 10:49:42 CET 2025


>      Q_PROPERTY_FULL(int, READ int value() noexcept,
>                      WRITE void setValue(int),
>                      NOTIFY void valueChanged())

Why all the ceremony? What people probably want is:

Q_DEFAULT_PROPERTY(int, value)

That would expand to:

     Q_PROPERTY(int value READ value WRITE setValue NOTIFY valueChanged)
public:
     int value() const { return m_value; }
     void setValue(int value)
     {
         if (value == m_value)
             return;
         m_value = value;
         Q_EMIT valueChanged();
     }
Q_SIGNALS:
     void valueChanged();
private:
     int m_value = {};

Now you just need to make sure you keep your Q_DEFAULT_PROPERTY in the 
private section of your class and you're fine. The capital "V" in 
"setValue" is probably challenging to express in a macro but otherwise 
this should be trivial.


More information about the Development mailing list