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. Custom Model with QML_ELEMENT
Forum Updated to NodeBB v4.3 + New Features

Custom Model with QML_ELEMENT

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 2 Posters 207 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
    sfabry
    wrote on last edited by
    #1

    I'm using cutom C++ model implementation and now declare it through QML_ELEMENT macro:

    class Person : public QSortFilterProxyModel
    {
        Q_OBJECT
        QML_ELEMENT
        Q_PROPERTY(QString name MEMBER m_name)
        Q_PROPERTY(QString lastname MEMBER m_lastname)
        Q_PROPERTY(int shoeSize MEMBER m_shoeSize)
    ...
    }
    

    Then i instanciate this class in my Qml file:

        Person {
            id: bob
            name: "Bob Jones"
            lastname: "Washington"
            shoeSize: 12
            sourceModel: null
        }
    

    The code is fine, the application runs fine BUT QtCreator don't recognize the property "sourceModel" (and all other QAbstractItemModel properties and signals) and throw me an M16 error "invalid property name"

    I just switched to QML_ELEMENT, before i was using qmlRegisterType and it was ok for QtCreator.
    Any idea what i'm doing wrong ?

    Thanks

    1 Reply Last reply
    0
    • GrecKoG Offline
      GrecKoG Offline
      GrecKo
      Qt Champions 2018
      wrote on last edited by
      #2

      Maybe try explicitly exposing QSortFilterProxyModel?

      struct QSortFilterProxyModelForeign
      {
          Q_GADGET
          QML_FOREIGN(QSortFilterProxyModel)
          QML_NAMED_ELEMENT(QSortFilterProxyModel) // or QML_ANONYMOUS
      };
      
      S 1 Reply Last reply
      0
      • GrecKoG GrecKo

        Maybe try explicitly exposing QSortFilterProxyModel?

        struct QSortFilterProxyModelForeign
        {
            Q_GADGET
            QML_FOREIGN(QSortFilterProxyModel)
            QML_NAMED_ELEMENT(QSortFilterProxyModel) // or QML_ANONYMOUS
        };
        
        S Offline
        S Offline
        sfabry
        wrote on last edited by
        #3

        @GrecKo said in Custom Model with QML_ELEMENT:

        Maybe try explicitly exposing QSortFilterProxyModel?

        struct QSortFilterProxyModelForeign
        {
            Q_GADGET
            QML_FOREIGN(QSortFilterProxyModel)
            QML_NAMED_ELEMENT(QSortFilterProxyModel) // or QML_ANONYMOUS
        };
        

        I tried without success...

        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