QML 中信号的奇怪问题
Weird issue with signals in QML
我有一个 class 继承自 QObject
。我在 class 中有一个 属性 声明为
Q_PROPERTY(QString errorString READ errorString)
在 QML 中,Qt Creator 建议使用 onErrorStringChanged
信号,这显然是只读的 属性。当我在 C++ 中对 class 的对象尝试 connect()
方法时,建议中也缺少相同的信号。
谁能解释一下哪里出了问题?
没有问题。您可以在这里阅读:http://doc.qt.io/qt-5/qtqml-syntax-objectattributes.html#property-attributes
Declaring a custom property implicitly creates a value-change signal
for that property, as well as an associated signal handler called
on<PropertyName>Changed
, where <PropertyName>
is the name of the
property, with the first letter capitalized.
QML 自动创建 onErrorStringChanged
信号,而在 C++ 中您必须自己定义它。
我有一个 class 继承自 QObject
。我在 class 中有一个 属性 声明为
Q_PROPERTY(QString errorString READ errorString)
在 QML 中,Qt Creator 建议使用 onErrorStringChanged
信号,这显然是只读的 属性。当我在 C++ 中对 class 的对象尝试 connect()
方法时,建议中也缺少相同的信号。
谁能解释一下哪里出了问题?
没有问题。您可以在这里阅读:http://doc.qt.io/qt-5/qtqml-syntax-objectattributes.html#property-attributes
Declaring a custom property implicitly creates a value-change signal for that property, as well as an associated signal handler called
on<PropertyName>Changed
, where<PropertyName>
is the name of the property, with the first letter capitalized.
QML 自动创建 onErrorStringChanged
信号,而在 C++ 中您必须自己定义它。