Congratulations to our 2022 Qt Champions!

qml settings overwritten on startup

  • Hi,

    I have a programm thats making serial communication w/ modbus
    I want to store the selected comport with qml settings .
    With this im storing the settings:

    Settings {
            property alias serialPortName: serialName.currentText

    And this is the combobox:

                ComboBox {
                    id: serialName
                    width: 200
                    model: Serial.portsNames

    After startup the property is overwritten by the first entry in the model. Any ideas how to fix this?
    Thanks in advance

  • @Slash200 The currentText property of ComboBox (Controls1 or 2) is read-only, it's probably the reason why it's not updated by Settings. Try currentIndex. It has a drawback that if the model is changed between the application version upgrades or dynamically between sessions it gives the wrong index. But it's difficult to handle versioning with Settings for anything, I think.

  • With currentIndex it behaves exactly the same

  • @Slash200 Using your code with ComboBox {... model: 2} and currentIndex works. So it must be something with the model. (currentText doesn't work, just as I thought.)

  • @Slash200 What is the output if you add to ComboBox

    onModelChanged: {console.log("model changed", model)}
    onCurrentIndexChanged: {console.log("index changed", currentIndex)}

Log in to reply