Unsolved QML : Error: Unknown method return type: QList<QStringList>
-
Hello, I have a function in Qt that returns QList<QStringList> object and I'm using it in a QML file. The compilation is fine. However, when executing it the QML throws this error : Unknown method return type: QList<QStringList>. Please help.
-
You need to register this type using
Q_DECLARE_METATYPE
. Also you'll probably need to useqRegisterType()
, but I'm not sure. Look it up in the documentation. -
Thank you for the reply. I tried different things but no success. Can you please give me an example?
-
@Iheb hi
you can return a QVariant instead of QList<QStringList>Q_INVOKABLE QVariant getlistOfLists(){ QList<QStringList> listOfLists; QStringList l1; l1<<"str1"; QStringList l2; l2<<"str2"; QStringList l3; l3<<"str3"; QStringList l4; l4<<"str4"; listOfLists<<l1<<l2<<l3<<l4; return QVariant::fromValue(listOfLists); }
Component.onCompleted: { var listsList = testObj.getlistOfLists() for(var i in listsList){ console.log(listsList[i][0]) } }