Important: Please read the Qt Code of Conduct -

Returning a QList<QGadget> from Q_INVOKABLE ?

  • Hello,
    Is it possible to return a QList (or other list type) of QGadgets from a C++ function to the calling QML?
    Normally I would expose a Q_PROPERTY holding the list, however in this case I need to return the list based on an input parameter. As far as I know this cannot be done with a Q_PROPERTY in any simply way?
    The use case is for a Repeater in QML.
    I am attempting to return a struct with some Q_PROPERTY's. The struct in question only needs to be read, and the list is there for the repeater.
    I have tried looking around for an answer, however almost all cases point to QObjects, or Q_PROPERTY's.

    Help would be much appreciated!

  • QVariantList can hold classes declared as Q_GADGET and can also be exposed to QML

  • Thanks, this works!