assign value from combobox to string
Solved
General and Desktop
-
This seems like it should be easy, but I can't find the right solution. I want to assign a value selected in a combobox to a string that gets used by a function.
Here is my code:
property string relayString: "" Shared.Button { id: pingRelay text: qsTr(" Ping Relay ") onClicked: { relayString = cboRelays.currentValue // <- error is here console.log("selected Relay: " + relayString) // troubleshooting id = "01A00640" qmlData = relayString pingBoard(id, qmlData) } } ComboBox { id: cboRelays textRole: "key" valueRole: "string" model: ListModel { ListElement { key: "Relay 1"; value: "1" } ListElement { key: "Relay 2"; value: "2" } ListElement { key: "Relay 3"; value: "3" } } }
When I click the button I get an error message: "Cannot assign [undefined] to QString".
-
@posktomten - thanks for the reply. Unfortunately that gives me the 'key' value ("Relay x"). What I want is the 'value' that goes with the key. So if 'Relay 2' is selected, it gives the string "2".
Hope that makes sense...
-