Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making a QPROPERTY read only in QT

Tags:

c++

qt

I have a property which does some calculation over the variable, but I don't want the reflected variable to reflect the UI, so I just need to do some calculations but the final result shouldn't reflect the UI in the property.

like image 297
احمد Avatar asked Sep 18 '25 16:09

احمد


1 Answers

Just don't add a write accessor, e.g.

class MyClass : public QObject
{
    Q_OBJECT
    Q_PROPERTY(int myVar READ myVar NOTIFY myVarChanged) //No WRITE ...

public:
    int myVar() const;

signals:
    void myVarChanged(int myVar);

private:
    int m_myVar;
}
like image 191
Felix Avatar answered Sep 20 '25 08:09

Felix