Exposing a Qlist of Qlist from Qt to qml and Exposing functions from main.cpp to qml and Iterating Qlist in Qml



  • Hi I Have the following class
    @
    class SourceSinkObj : public QObject
    {
    Q_OBJECT
    Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
    Q_PROPERTY(QString color READ color WRITE setColor NOTIFY colorChanged)
    @

    and

    @
    class ListofLists : public SourceSinkObj
    {
    Q_OBJECT
    Q_PROPERTY(quint32 ident READ ident WRITE setident NOTIFY identChanged)
    Q_PROPERTY( QList<SourceSinkObj*> sublist READ sublist WRITE setsublist NOTIFY sublistChanged)
    @

    in my Main .cpp i do the following

    @
    QList<ListofLists*> SinkMasterlist;

    for (int i=0 ;i < listSinkClasses.size() ;i++)
    {
    am_SinkClass_s tempSinkClass;
    tempSinkClass= listSinkClasses.at(i);
    ListofLists* TempSinkMaster = new ListofLists();
    quint32 TempID= tempSinkClass.SinkClassID;
    TempSinkMaster->setident(TempID);
    SinkMasterlist.append(TempSinkMaster);

    }
    @

    and added the following to register metatypes

    @
    #ifndef REGISTER_METATYPES
    #define REGISTER_METATYPES
    qRegisterMetaType<ListofLists*>();
    qRegisterMetaType<QList <ListofLists*> >(); \

    #endif

    Q_DECLARE_METATYPE(ListofLists*);
    Q_DECLARE_METATYPE(QList<ListofLists*>);
    @

    When I try exposing the Qlist in main.pp I get a segmentation fault

    @
    ctxt->setContextProperty("SinkMasterlist", QVariant::fromValue(SinkMasterlist));
    @

    Please Help me with

    1. correcting to avoid crash
      2.How to expose functions in main to Qml. I am assuming I cannot use Q_Invokable in this case
      3.How do I iterate through a Qlist in Qml
      Thanks

    [EDIT: fixed code formatting, Volker]



  • I resolved the crash by QList<Qobject*> SinkMasterlist;.
    help me resolve the rest


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.