Is it possible to assign different types to a role in a ListElement ?
Unsolved
QML and Qt Quick
-
Dear Qt'ers, please, take a look at the following code:
ListModel { ListElement { display: "foo"; type: EType.EText; // EType is my own enum, loader selects the source component based on the value of this role comboData: [] } ListElement { display: 1; //<-- want to use index 1 in the combo box type: EType.EList; comboData: [ ListElement { display: "one" }, ListElement { display: "two" } ] } }
This is a mock table of one implemented in C++. Everything looks fine except that I'm getting a warning :
<Unknown File>: Can't assign to existing role 'display' of different type [Number -> String]
Again, the index of the combo box is set correctly, the value is "two", but I'm wondering how do I handle this warning ?
-
@LRDPRDX
You can’t assign different types to the same role, if you populate via QJSValue.
In that case you could just use another data role, e.g. edit instead of display.
I recently played with a combo box in a table view and ended up doing it that way. -
@Axel-Spoerl Thank you. Actually, I've found that putting a string also works :
ListElement { display: "1" ... }