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

Qt.resolvedUrl destroys followed by properties of a model item

    XMLWordPrintable

Details

    • Windows
    • 7c6d9d8bf07c34186f96ec1cde74961358f567ec 75f957f87a9341af5d3266166ae9996dbf79da2b

    Description

      Qt 5.12 - works fine.

      Qt 6.2 - model item's properties can't be set and just ignored by QML after setting a property using Qt.resolvedUrl. Please look at startListModel function's code.

      Code:

      import QtQuick 2.12
      import QtQuick.Window 2.12
      import QtQuick.Controls 2.12
      import QtQuick.Layouts 1.12
      
      Window {
          id: root
      
          width: 640
          height: 480
          visible: true
          title: qsTr("Hello World")
      
          signal browserBtnClicked()
      
      
          ListView {
              anchors.fill: parent
              currentIndex: -1
      
              delegate: ItemDelegate {
                  opacity: model.enabled ? 1 : 0.3
      
                  width: parent.width
                  highlighted: ListView.isCurrentItem
                  leftPadding: 20
      
                  onClicked: {
                      if (model.enabled)
                      {
                          root.close()
                          listModel.actions[model.actionLabel]();
                      }
                  }
      
                  contentItem: Row {
                      anchors.verticalCenter: parent.verticalCenter
                      width: parent.width
                      spacing: 15
      
                      Label {
                          text: qsTr(model.text)
                          font.pixelSize: 15
                          wrapMode: Text.WordWrap
                          horizontalAlignment: Text.AlignLeft
                          width: parent.width - 24 - parent.spacing
                          anchors.verticalCenter: parent.verticalCenter
                      }
                  }
              }
      
              model: listModel
          }
      
          ListModel {
              id: listModel
      
              property var actions : {
                  "browser": function(){ root.browserBtnClicked()},
                  "quit": function(){ Qt.quit(); },
              }
      
              function startListModel() {
                  clear();
      
                  append({
                             "text": QT_TR_NOOP("Browser"),
                             "icon": Qt.resolvedUrl("../images/mobile/browser.svg"),
                             'actionLabel': "browser",
                             "enabled": true
                         });
      
                  append({
                             "text": QT_TR_NOOP("Quit"),
                             "icon": Qt.resolvedUrl("../images/mobile/quit.svg"),
                             'actionLabel': "quit",
                             "enabled": true
                         });
      
                  // BUG WORKAROUND: just put Qt.resolvedUrl last
                  append({
                             "text": QT_TR_NOOP("Quit [BUG WORKAROUND: different order]"),
                             'actionLabel': "quit",
                             "enabled": true,
                             "icon": Qt.resolvedUrl("../images/mobile/quit.svg")
                         });
              }
          }
      
          Component.onCompleted: {
              listModel.startListModel();
          }
      }
      
      

      Attachments

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

        Activity

          People

            ulherman Ulf Hermann
            alervd Alexander Dyagilev
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes