Automatic conversion of QList<QString> is not a JS array of strings?
Solved
QML and Qt Quick
-
Hi.
I wish to set the model of aListView
to aQList<QString>
passed from C++ via aQ_INVOKABLE
function call.According to the Qt docs, the conversion from
QList<QString>
to a JavaScript array is automatic.Yet, the view does not show the data. If I set the model directly in QML to a JS string array with exactly the same strings however it works.
Converting it explictly to a JS array withArray.from()
also works.property var names: [] Component.onCompleted: { names = um.getNames() //console.debug(names) //<-- shows [Name1,Name2] //view.model = ["Name1", "Name2"] //<-- WORKS //view.model = [names[0], names[1]] //<-- WORKS //view.model = Array.from(names) //<-- WORKS view.model = names // <-- DOES NOT WORK ?? }
What am I missing here? Is the implicit conversion done by the QML engine of a
QList<QString>
not a normal JS array of strings? -
Have you tried with QStringList?