[Interest] QML Set data from a different model role

NoRulez norulez at me.com
Mon May 9 16:32:52 CEST 2016


I have a QStandardItemModel

I also to overload the roleNames() function but then i get the error that "Role2" isn't defined.



> Am 09.05.2016 um 15:50 schrieb Nikita Krupenko <krnekit at gmail.com>:
> 
> 2016-05-09 9:19 GMT+03:00 NoRulez <norulez at me.com>:
>> Hi,
>> 
>> I want do show data in a combobox in QML and after a selection in the combo box is made I want the data but from a different role.
>> 
>> In QML I have the following:
>> 
>> ComboBox {
>> model: MyModel
>> textRole: "Role1"
>> onCurrentTextChanged: {
>>        MyLineEdit.text = ?????? // Here I want the text from "Role2"
>>    }
>> }
>> 
>> MyLineEdit is a QML LineEdit
>> The text for "Role1" works already.
>> Could anybody please give me a help
>> 
>> Thanks
>> _______________________________________________
>> Interest mailing list
>> Interest at qt-project.org
>> http://lists.qt-project.org/mailman/listinfo/interest
> 
> AFAIK, you have ho access to model data in ComboBox. But, you can get
> it directly from model, like:
> 
> MyLineEdit.text = MyModel.get(currentIndex)["Role2"]
> 
> if you use ListModel, or some similar way if you have different model.



More information about the Interest mailing list