Warning about non-NOTIFYable properties in QML
If the property values can change, then QML needs a NOTIFY
signal so it can know when they have changed and update property bindings.
If they can't change, add CONSTANT
to your property declaration, for example:
Q_PROPERTY(QString simplified READ simplified CONSTANT).
In your case, there are set methods, which implies the properties can change, but if they don't change when they're being used in your QML, you can get rid of the warnings by marking them as CONSTANT
.
Related videos on Youtube
laurent
Updated on July 10, 2020Comments
-
laurent almost 4 years
I have a QML based application in Qt that generates some warnings at runtime:
QDeclarativeExpression: Expression "(function $text() { return pinyin })" depends on non-NOTIFYable properties: hanzi::DictionaryEntry::pinyin
I believe it refers to this class which has some properties with no notifier (because not needed):
#ifndef DICTIONARYENTRY_H #define DICTIONARYENTRY_H namespace hanzi { class DictionaryEntry : public QObject { Q_OBJECT Q_PROPERTY(QString simplified READ simplified) Q_PROPERTY(QString traditional READ traditional) Q_PROPERTY(QString pinyin READ pinyin) Q_PROPERTY(QString definition READ definition) public: explicit DictionaryEntry(QObject* parent = 0); const QString& simplified() const; const QString& traditional() const; const QString& pinyin() const; const QString& rawDefinition() const; const QStringList& definitions() const; const QString& definition() const; void setSimplified(const QString& v); void setTraditional(const QString& v); void setPinyin(const QString& v); void setDefinitions(const QStringList& v); }; } #endif // DICTIONARYENTRY_H
Does anybody know why it's showing these warnings, and, if they are not important, is there any way to disable them?
-
AndroC about 5 yearsThe property I'm passing is also declared in qml. How can I make it constant?
-
laurapons almost 5 yearsWhat about if those qt properties can change, but not on that specific QML? For example, a class called user with email, PIN, password,... fields. On login page, none of the properties can be modified, but once the user logs in, they can. Is it possible to disable these warnings for a specific QML component? can we define on QML side: "property static string password = user.password"?
-
pooya13 about 3 yearsI don't think the fact that they have set methods makes a difference here. I am getting this error even without the set method. I wonder why the Qt documentation has this as an example instead:
Q_PROPERTY(bool focus READ hasFocus)