Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Returning a multiple QObject derivated pointer class from a Q_INVOKABLE parameters
QtWS25 Last Chance

Returning a multiple QObject derivated pointer class from a Q_INVOKABLE parameters

Scheduled Pinned Locked Moved QML and Qt Quick
qabstractlistmoqinvokableparameter
2 Posts 1 Posters 1.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    Erakis
    wrote on last edited by Erakis
    #1

    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,

    1 Reply Last reply
    0
    • E Offline
      E Offline
      Erakis
      wrote on last edited by Erakis
      #2

      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 ?

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved