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. Exposing a Qlist of Qlist from Qt to qml and Exposing functions from main.cpp to qml and Iterating Qlist in Qml
Qt 6.11 is out! See what's new in the release blog

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

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 1 Posters 3.2k Views 1 Watching
  • 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.
  • S Offline
    S Offline
    sruthihsr
    wrote on last edited by
    #1

    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]

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sruthihsr
      wrote on last edited by
      #2

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

      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