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. qml settings overwritten on startup
QtWS25 Last Chance

qml settings overwritten on startup

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
5 Posts 2 Posters 1.1k 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.
  • S Offline
    S Offline
    Slash200
    wrote on last edited by
    #1

    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
    0
    • S Slash200

      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 Offline
      E Offline
      Eeli K
      wrote on last edited by Eeli K
      #2

      @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
      1
      • S Offline
        S Offline
        Slash200
        wrote on last edited by
        #3

        With currentIndex it behaves exactly the same

        E 2 Replies Last reply
        0
        • S Slash200

          With currentIndex it behaves exactly the same

          E Offline
          E Offline
          Eeli K
          wrote on last edited by
          #4

          @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
          0
          • S Slash200

            With currentIndex it behaves exactly the same

            E Offline
            E Offline
            Eeli K
            wrote on last edited by
            #5

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

            • Login

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