[Interest] QML Set data from a different model role

NoRulez norulez at me.com
Mon May 9 17:24:36 CEST 2016


Ok thanks, I will give it a try

> Am 09.05.2016 um 17:17 schrieb Nikita Krupenko <krnekit at gmail.com>:
> 
> 2016-05-09 18:12 GMT+03:00 NoRulez <norulez at me.com>:
>> This works when I use a number (256 for Qt::UserRole) but not with an enum name
>> 
>>> Am 09.05.2016 um 16:47 schrieb Nikita Krupenko <krnekit at gmail.com>:
>>> 
>>> 2016-05-09 17:32 GMT+03:00 NoRulez <norulez at me.com>:
>>>> 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.
>>> 
>>> So, you need to use data() method. But you need to pass here
>>> QModelIndex, which you could get only from DelegateModel, which not
>>> used here :) I think, you can add to your model method, that return
>>> data by an integer index and use it here.
>>> _______________________________________________
>>> Interest mailing list
>>> Interest at qt-project.org
>>> http://lists.qt-project.org/mailman/listinfo/interest
> 
> I think you need to register your model by qmlRegisterType(). Then,
> after you import module you registered you type in, it should be
> possible to use MyModel.Role2 in QML.



More information about the Interest mailing list