Details
-
Bug
-
Resolution: Fixed
-
P1: Critical
-
6.4
-
2c0518eb62ebe475abf84b8ee2fd50c53720d3a4 66a30b9a33aac288335f32ea9dc8dd8542abf69f
Description
Consider:
Q_PROPERTY(int score BINDABLE scoreBindable FINAL) public: QBindable<int> scoreBindable() { return QBindable<int>(&m_score); } private: QProperty<int> m_score;
This should be enough to define a property that QML can read, write and be notified about. You can do all of that through the bindable after all. Unfortunately it isn't. Consider:
import QtQml import samegame Score { id: root score: 10 property int highscore: 0 onScoreChanged: if (score > highscore) highscore = score property Timer t: Timer { interval: 10 running: true repeat: true onTriggered: { root.score += 10; console.log(root.score, root.highscore) } } }
Results in:
QQmlApplicationEngine failed to load component
qrc:/QtExamples/samegame/scoreUser.qml:6:12: Invalid property assignment: "score" is a read-only property
Now, explicitly opting into write support may be a good thing, but defining a WRITE accessor for that is silly.
Another, even worse, problem is that we do not get proper notifications through the bindable either. If we do the writing through C++, onScoreChanged is actually triggered, but if we then read the score, it is 0.
Attachments
Issue Links
- relates to
-
QTBUG-112617 Bindable-only properties of type qreal/double don't work from QML
- Closed
For Gerrit Dashboard: QTBUG-97249 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
415207,5 | Add test to verify we can read through a bindable-only property | dev | qt/qtdeclarative | Status: MERGED | +2 | 0 |
415216,7 | moc: Allow reading property values through bindables | dev | qt/qtbase | Status: MERGED | +2 | 0 |
415259,11 | moc: Allow writing properties through bindables | dev | qt/qtbase | Status: MERGED | +2 | 0 |