Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Call for Presentations - Qt World Summit

    Unsolved qml settings overwritten on startup

    QML and Qt Quick
    2
    5
    835
    Loading More Posts
    • 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.
    • S
      Slash200 last edited by

      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

      E 1 Reply Last reply Reply Quote 0
      • E
        Eeli K @Slash200 last edited by Eeli K

        @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.

        1 Reply Last reply Reply Quote 1
        • S
          Slash200 last edited by

          With currentIndex it behaves exactly the same

          E 2 Replies Last reply Reply Quote 0
          • E
            Eeli K @Slash200 last edited by

            @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.)

            1 Reply Last reply Reply Quote 0
            • E
              Eeli K @Slash200 last edited by

              @Slash200 What is the output if you add to ComboBox

              onModelChanged: {console.log("model changed", model)}
              onCurrentIndexChanged: {console.log("index changed", currentIndex)}
              
              1 Reply Last reply Reply Quote 0
              • First post
                Last post