PDA

View Full Version : Should Q_PROPERTY always be CONSTANT or NOTIFY?



tuli
13th November 2022, 07:35
Hi,

I have a Q_PROPERTY like so:


Q_PROPERTY(QString name READ name WRITE setName)

clazy warns that


a non-CONSTANT Q_PROPERTY is missing a NOTIFY signal.

https://github.com/KDE/clazy/blob/1.11/docs/checks/README-qproperty-without-notify.md


Why is that? In my case it cant be CONSTANT because it has a WRITE setter. But it cant be NOTIFY either because there is no signal fired when it is set.
I am rarely using Q_PROPERTY, so my best guess is it's not the right tool for the case I am describing. If so, why not?


Qt doc (https://doc.qt.io/qt-6/properties.html) also has some examples that look just like mine.

john_god
20th November 2022, 21:43
According the qt doc you posted the notify signal is optional so you're good like that, that should be just a warning. If you want to ger rid of that warning, just add a notify signal, even if you dont need it


Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)

// you have to declare the notify signal
signals:
void nameChanged(int newName);