Returning a multiple QObject derivated pointer class from a Q_INVOKABLE parameters
-
Hi,
I'm created an QAbstractListModel derived class from a CPP INVOKABLE method. Here the declaration :
class CustomModelList : public QAbstractListModel { Q_OBJECT Q_PROPERTY(QString title READ title NOTIFY titleChanged) . . . } Q_DECLARE_METATYPE(CustomModelList *)
On the CPP side, I have a CPP mediator set as context in the QQmlApplicationEngine. It is exposing a method to create two list at time :
Q_INVOKABLE bool createListModel(CustomModelList* pList1, CustomModelList* pList2) { pList1 = new CustomModelList ("List #1", this); pList1 = new CustomModelList ("List #2", this); }
And on the QML side, here is how I call it
var t1, t2; manager.createListModel(t1, t2); // t1 and t2 are always undefined after calling this function !
I tried using QObject* instead of CustomModelList* as parameter but I got the same negative result. I tried also QVariant* but always the same "undefined" result.
Obviously, it works doing this :
Q_INVOKABLE QObject* createListModel() { return new CustomModelList ("List #1", this); } // Qml side var t1 = manager.createListModel();
But this is not what I need.
Is there a way to create object on CPP using parameters of a method and then getting it on QML side ?Best regards,
-
From the QT documentation it seem to be possible : Exposing Attributes of C++ Types to QML
Any data that is transferred from C++ to QML, whether as a property value, a method parameter or return value, or a signal parameter value, must be of a type that is supported by the QML engine.
So why it is not working ? Is any of you succeed returning one or more object through method parameters ?