关于 QML 中不可通知属性的警告
我在 Qt 中有一个基于 QML 的应用程序,它在运行时生成一些警告:
QDeclarativeExpression: 表达式 "(function $text() { return 拼音 })" 取决于不可通知的属性: 汉字::DictionaryEntry::拼音
我相信它指的是这个类,它有一些没有通知器的属性(因为不需要):
#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
有人知道为什么它显示这些警告,如果它们不重要,有没有办法禁用他们?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果属性值可以更改,则 QML 需要一个 NOTIFY 信号,以便它可以知道它们何时更改并更新属性绑定。
如果它们无法更改,请将
CONSTANT
添加到您的属性声明中,例如:在您的情况下,有 set 方法,这意味着属性可以更改,但如果它们在更改时不更改当您在 QML 中使用这些警告时,您可以通过将它们标记为
CONSTANT
来消除警告。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: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
.