Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. "currentValue" is a read-only property of ComboBox
Forum Updated to NodeBB v4.3 + New Features

"currentValue" is a read-only property of ComboBox

Scheduled Pinned Locked Moved Solved QML and Qt Quick
comboboxqtquickqmlbug
4 Posts 3 Posters 309 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    eschutz
    wrote on last edited by
    #1

    I am trying to run the (minimally modified) example for Model Roles on the ComboBox QML Type:

    import QtQuick
    import QtQuick.Controls
    
    ApplicationWindow {
        width: 640
        height: 480
        visible: true
    
        // Used as an example of a backend - this would usually be
        // e.g. a C++ type exposed to QML.
        QtObject {
            id: backend
            property int modifier: Qt.NoModifier
        }
    
        ComboBox {
            model: [
                { value: Qt.NoModifier, text: qsTr("No modifier") },
                { value: Qt.ShiftModifier, text: qsTr("Shift") },
                { value: Qt.ControlModifier, text: qsTr("Control") }
            ]
            textRole: "text"
            valueRole: "value"
            // Set currentValue to the value stored in the backend.
            currentValue: backend.modifier
            // When an item is selected, update the backend.
            onActivated: backend.modifier = currentValue
        }
    }
    

    Running this with pyside6-qml produces the error Invalid property assignment: "currentValue" is a read-only property. This example is taken directly from the documentation. How can I set the value of the combo box?

    1 Reply Last reply
    0
    • GrecKoG Offline
      GrecKoG Offline
      GrecKo
      Qt Champions 2018
      wrote on last edited by
      #3

      currentValue is writeable since Qt 6.10 only.

      1 Reply Last reply
      2
      • B Offline
        B Offline
        Bandler
        wrote on last edited by
        #2

        You can set the current index instead with something like that:

        Component.onCompleted: {
             let index = indexOfValue(backend.modifier);
             if (index >= 0) {
                      currentIndex = index
             }
        }
        
        1 Reply Last reply
        0
        • GrecKoG Offline
          GrecKoG Offline
          GrecKo
          Qt Champions 2018
          wrote on last edited by
          #3

          currentValue is writeable since Qt 6.10 only.

          1 Reply Last reply
          2
          • E eschutz has marked this topic as solved on
          • E Offline
            E Offline
            eschutz
            wrote on last edited by
            #4

            Apparently I was running 6.9.3. Code works in 6.10. Thank you!

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved