[Solved] QML ComboBox model from C++
-
Hey!
I have a list from C++ containing language code, language description and a flag for the corresponding country.
I made the connection to QML, but cant get to set the model right.
I tried different approaches and either I get an empty ComboBox, or I get a ComboBox containing only one alternative, which is "0".This is the code for the ComboBox:
@
ComboBox{
id: langSelection;
editable: false;
width: caText.width;
model: LanguageList.languageList;textRole:{ if(LanguageList.langList.langCode !== undefined){ LanguageList.langList.langCode; } }
@
-
Hi,
I'm not sure if this is correct but I use QVariantList with strings for ComboBox. For example:
@
QVariantList MslHelpers::keychainActionTypeList()
{
QVariantList list;
list.clear();list.append("Unknown Action"); list.append("Save Datas Action"); list.append("Remove Datas By Kyes Action"); return list;
}
@and used it like this:
@
ComboBox {
id: keychaninActionBox
width: 200
model: manager.typeManager.keychainActionTypeList()
}
@ -
You can look at the examples given in <QtInstallDir>\examples\quick\models about exporting C++ models to QML ?
Also ComboBox has 'model' property. You should be able to set this property by model which is exposed from C++.
-
Thanks for the replies, but I got it to work, I set it up like this:
@
ComboBox{
id: comboBox;
width: caText.width;
model: languageList.langList;
textRole: "langDescription";
}
@