Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-97249

Properly support properties with BINDABLE

    XMLWordPrintable

    Details

    • Commits:
      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

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

            Assignee:
            ulherman Ulf Hermann
            Reporter:
            ulherman Ulf Hermann
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Gerrit Reviews

                There are no open Gerrit changes