Details
-
Type:
Bug
-
Status: Closed
-
Priority:
Not Evaluated
-
Resolution: Duplicate
-
Affects Version/s: 5.12.5
-
Fix Version/s: 5.14.0 Alpha
-
Component/s: QML: Declarative and Javascript Engine
-
Labels:
-
Commits:da14688140550879e376e71cf273b16494e6c3c4
Description
myWindow.text and qmlWindow.text is not changed, while root.value is changed to 'null' from some value.
What I expected myWindow.text and qmlWindow.text are also updated through the Bindings.
Test code.
main.cpp
#include <QGuiApplication> #include <QQuickView> #include <QQmlContext> class MyView: public QQuickView { Q_OBJECT Q_PROPERTY(QObject *test READ test WRITE setTest NOTIFY testChanged) public: void init() { rootContext()->setContextProperty(QLatin1String("myWindow"), this); } QObject *test() { return m_test; } void setTest(QObject *t) { qInfo() << "setTest" << t << m_test; m_test = t; emit testChanged();} signals: void testChanged(); private: QObject *m_test = nullptr; }; int main(int argc, char *argv[]) { QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QGuiApplication app(argc, argv); const QUrl url(QStringLiteral("qrc:/main.qml")); MyView view; view.init(); view.setSource(url); view.show(); return app.exec(); } #include "main.moc"
import QtQuick 2.12 import QtQuick.Window 2.12 Rectangle { id: root visible: true width: 640 height: 480 color: "red" property var myValue: -1 MouseArea { anchors.fill: parent onClicked: { root.toggle(); } } function toggle() { if (root.myValue == null) { root.color = "yellow" console.log("set to root") root.myValue = root } else { root.color = "red" console.log("set to null") root.myValue = null } } Item { id: qmlWindow property var test: null onTestChanged: console.log("qmlWindow", test) } Binding { target: myWindow property: "test" value: root.myValue } Binding { target: qmlWindow property: "test" value: root.myValue } }
Attachments
Issue Links
- duplicates
-
QTBUG-77027 Binding QML is not working in some situations
-
- Closed
-