Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert comma separated substrings of a large string into variant array elements in QML

Tags:

c++

qt

qml

OK, So I'm fairly new to the Qt5 QML framework. This would've been fairly easy in any other language such as Java etc. But I'm unable to accomplish this in QML.

Here's what I want to do: I want to take a long string that I've received from my c++ code separated by commas

 property string: "Here,There,That,This" 

and I want to split it up into separate strings. I've come to understand that you need to use a variant in the sense that I basically have the property

property variant stringlist 

where, stringlist[0] = "Here" and stringlist[1] = "There" etc.

Does anyone have a suggestion for the code for a function that I can call to do it. I would like to refrain from needing a javascript addition to create this function. So please do try to suggest a QML centric function, if at all possible.

like image 719
Ra41P Avatar asked Sep 15 '25 06:09

Ra41P


1 Answers

Item{
  property string myString: "Here,There,That,This"
  property variant stringList: myString.split(',')

  Component.onCompleted: {
    console.log(stringList[0]); //outputs 'Here'
  }
}
like image 121
Skogen Avatar answered Sep 17 '25 19:09

Skogen