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

Crash when print delegateModel of Combobox

    XMLWordPrintable

Details

    • Windows

    Description

      the documents says like below:

      https://doc.qt.io/qt-5/qtquickcontrols2-customize.html#customizing-combobox

       

      // code placeholder
      popup: Popup {
              y: control.height - 1
              width: control.width
              implicitHeight: contentItem.implicitHeight
              padding: 1
      
              contentItem: ListView {
                  clip: true
                  implicitHeight: contentHeight
                  model: control.popup.visible ? control.delegateModel : null
                  currentIndex: control.highlightedIndex
      
                  ScrollIndicator.vertical: ScrollIndicator { }
              }
      
              background: Rectangle {
                  border.color: "#21be2b"
                  radius: 2
              }
          }
      

      But when I try to print the delegateModel  by JSON.stringfy, the app crashs. 

      // code placeholder
      import QtQuick 2.15
      import QtQuick.Window 2.15
      import QtQuick.Controls 2.12
      Window {
          width: 640
          height: 480
          visible: true
          title: qsTr("Hello World")
          ComboBox {
              id: control
              model: ["First", "Second", "Third"]
      
              delegate: ItemDelegate {
                  width: control.width
                  contentItem: Text {
                      text: modelData
                      color: "red"
                      font: control.font
                      elide: Text.ElideRight
                      verticalAlignment: Text.AlignVCenter
                  }
                  highlighted: control.highlightedIndex === index
              }
      
      
      
              contentItem: Text {
                  leftPadding: 0
                  rightPadding: control.indicator.width + control.spacing
      
                  text: control.displayText
                  font: control.font
                  color: control.pressed ? "#black" : "#red"
                  verticalAlignment: Text.AlignVCenter
                  elide: Text.ElideRight
              }
      
              background: Rectangle {
                  implicitWidth: 120
                  implicitHeight: 50
                  border.color: control.pressed ? "#blue" : "#blue"
                  border.width: control.visualFocus ? 2 : 1
                  radius: 2
              }
      
              popup: Popup {
                  y: control.height - 1
                  width: control.width
                  implicitHeight: contentItem.implicitHeight
                  padding: 1
      
                  contentItem: ListView {
                      clip: true
                      implicitHeight: contentHeight
                      model:  control.delegateModel
                      currentIndex: control.highlightedIndex
      
                      ScrollIndicator.vertical: ScrollIndicator { }
                  }
      
                  background: Rectangle {
                      border.color: "#21be2b"
                      radius: 2
                  }
              }
      
          }
          Button{
              x:200
              width: 100
              height: 40
              onClicked: {
                  console.log(JSON.stringify(control.delegateModel))
              }
          }
      }
      

       

      Attachments

        Issue Links

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

          Activity

            People

              qtqmlteam Qt Qml Team User
              yorkxychen york123 chen123
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes