<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Returning a multiple QObject derivated pointer class from a Q_INVOKABLE parameters]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">I'm created an QAbstractListModel derived class from a CPP INVOKABLE method. Here the declaration :</p>
<pre><code>class CustomModelList : public QAbstractListModel
{
    Q_OBJECT
    Q_PROPERTY(QString title READ title NOTIFY titleChanged)
     . . .
}
Q_DECLARE_METATYPE(CustomModelList  *)
</code></pre>
<p dir="auto">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 :</p>
<pre><code>Q_INVOKABLE bool createListModel(CustomModelList* pList1, CustomModelList* pList2)
{
    pList1 = new CustomModelList ("List #1", this);
    pList1 = new CustomModelList ("List #2", this);
}
</code></pre>
<p dir="auto">And on the QML side, here is how I call  it</p>
<pre><code>var t1, t2;
manager.createListModel(t1, t2);

// t1 and t2 are always undefined after calling this function !
</code></pre>
<p dir="auto">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.</p>
<p dir="auto">Obviously, it works doing this :</p>
<pre><code>Q_INVOKABLE QObject* createListModel()
{
    return new CustomModelList ("List #1", this);
}
// Qml side
var t1 = manager.createListModel();
</code></pre>
<p dir="auto">But this is not what I need.<br />
Is there a way to create object on CPP using parameters of a method and then getting it on QML side ?</p>
<p dir="auto">Best regards,</p>
]]></description><link>https://forum.qt.io/topic/58861/returning-a-multiple-qobject-derivated-pointer-class-from-a-q_invokable-parameters</link><generator>RSS for Node</generator><lastBuildDate>Mon, 10 Aug 2026 00:59:39 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/58861.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 14 Sep 2015 22:47:05 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Returning a multiple QObject derivated pointer class from a Q_INVOKABLE parameters on Wed, 16 Sep 2015 12:02:36 GMT]]></title><description><![CDATA[<p dir="auto">From the QT documentation it seem to be possible : <a href="http://doc.qt.io/qt-5/qtqml-cppintegration-exposecppattributes.html" target="_blank" rel="noopener noreferrer nofollow ugc">Exposing Attributes of C++ Types to QML</a></p>
<p dir="auto">Any data that is transferred from C++ to QML, whether as a property value, <strong>a method parameter</strong> or return value, or a signal parameter value, must be of a type that is supported by the QML engine.</p>
<p dir="auto">So why it is not working ? Is any of you succeed returning one or more object through method parameters ?</p>
]]></description><link>https://forum.qt.io/post/290487</link><guid isPermaLink="true">https://forum.qt.io/post/290487</guid><dc:creator><![CDATA[Erakis]]></dc:creator><pubDate>Wed, 16 Sep 2015 12:02:36 GMT</pubDate></item></channel></rss>