Qt 6.11 is out! See what's new in the release
blog
Automatic conversion of QList<QString> is not a JS array of strings?
-
Hi.
I wish to set the model of aListViewto aQList<QString>passed from C++ via aQ_INVOKABLEfunction 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?
-
@GrecKo
QStringListworks without conversion toArray. So only theQList<QString>conversion is not transparent.Thanks.