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. Warning when creating instantiable object type
Forum Updated to NodeBB v4.3 + New Features

Warning when creating instantiable object type

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 2 Posters 1.1k 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.
  • K Offline
    K Offline
    KejPi
    wrote on 20 Dec 2023, 21:07 last edited by
    #1

    Hello guys,

    I was following this documentation to create instantiable QSortFilterProxyModel in QML but is get some warning that is even not related to the proxy model itself.

    I have a QML implementation of EPG that is created inside a QDialog inherited class constructor:

        QQuickView *qmlView = new QQuickView();
    
        QQmlContext * context = qmlView->rootContext();
        context->setContextProperty("slModel", m_serviceListModel);
        context->setContextProperty("epgDialog", this);
    
        qmlView->setColor(Qt::transparent);
        qmlView->setSource(QUrl("qrc:/programmeguide/qml/epg.qml"));
    
        qRegisterMetaType<EPGModel>("EPGModel");
    
        QWidget *container = QWidget::createWindowContainer(qmlView, this);
    
        QVBoxLayout * layout = new QVBoxLayout(this);
        layout->addWidget(container);
    

    In order to make it working, this is in my cmake file:

    qt6_add_qml_module(${TARGET}
        URI programmeguide
        QML_FILES
            qml/epg.qml
        VERSION 1.0
    )
    

    And it works as expected but I need a proxy model, that I need to instantiate in QML. So following the documentation, I have created a C++ class:

    class EPGProxyModel : public QSortFilterProxyModel
    {
        Q_OBJECT
        QML_ELEMENT
    public:
        explicit EPGProxyModel(QObject *parent = nullptr);
    };
    

    And I have added the files to cmake:

    qt6_add_qml_module(${TARGET}
        URI programmeguide
        QML_FILES
            qml/epg.qml
        SOURCES epgproxymodel.h epgproxymodel.cpp
        VERSION 1.0
    )
    

    And I have also added this to epg.qml:

    import programmeguide
    

    Since I did this I get following warning:

    SLModel is neither a QObject, nor default- and copy-constructible, nor uncreatable. You should not use it as a QML type.
    

    SLModel is used inside QML as slModel and actually it should be the source model for proxy model. It was working in QML as expected before starting with proxy model integration and it is declared as follows:

    class SLModel : public QAbstractItemModel
    {
        Q_OBJECT
        QML_ELEMENT
    
    public:
        explicit SLModel(const ServiceList * sl, const MetadataManager * mm, QObject *parent = 0);
        ~SLModel();
        // ...
    

    It means it is both Q_OBJECT and QML_ELEMENT.

    I have tried to reduce QML and I get the warning even with such simple qml like this (SLModel not used at all):

    import QtQuick
    import programmeguide
    Item {
            id: mainItemId
            anchors.fill: parent
    }
    

    To be honest, I have no idea what is going wrong. Do you have any hint? Thanks!

    J 1 Reply Last reply 20 Dec 2023, 22:31
    0
    • K KejPi
      20 Dec 2023, 21:07

      Hello guys,

      I was following this documentation to create instantiable QSortFilterProxyModel in QML but is get some warning that is even not related to the proxy model itself.

      I have a QML implementation of EPG that is created inside a QDialog inherited class constructor:

          QQuickView *qmlView = new QQuickView();
      
          QQmlContext * context = qmlView->rootContext();
          context->setContextProperty("slModel", m_serviceListModel);
          context->setContextProperty("epgDialog", this);
      
          qmlView->setColor(Qt::transparent);
          qmlView->setSource(QUrl("qrc:/programmeguide/qml/epg.qml"));
      
          qRegisterMetaType<EPGModel>("EPGModel");
      
          QWidget *container = QWidget::createWindowContainer(qmlView, this);
      
          QVBoxLayout * layout = new QVBoxLayout(this);
          layout->addWidget(container);
      

      In order to make it working, this is in my cmake file:

      qt6_add_qml_module(${TARGET}
          URI programmeguide
          QML_FILES
              qml/epg.qml
          VERSION 1.0
      )
      

      And it works as expected but I need a proxy model, that I need to instantiate in QML. So following the documentation, I have created a C++ class:

      class EPGProxyModel : public QSortFilterProxyModel
      {
          Q_OBJECT
          QML_ELEMENT
      public:
          explicit EPGProxyModel(QObject *parent = nullptr);
      };
      

      And I have added the files to cmake:

      qt6_add_qml_module(${TARGET}
          URI programmeguide
          QML_FILES
              qml/epg.qml
          SOURCES epgproxymodel.h epgproxymodel.cpp
          VERSION 1.0
      )
      

      And I have also added this to epg.qml:

      import programmeguide
      

      Since I did this I get following warning:

      SLModel is neither a QObject, nor default- and copy-constructible, nor uncreatable. You should not use it as a QML type.
      

      SLModel is used inside QML as slModel and actually it should be the source model for proxy model. It was working in QML as expected before starting with proxy model integration and it is declared as follows:

      class SLModel : public QAbstractItemModel
      {
          Q_OBJECT
          QML_ELEMENT
      
      public:
          explicit SLModel(const ServiceList * sl, const MetadataManager * mm, QObject *parent = 0);
          ~SLModel();
          // ...
      

      It means it is both Q_OBJECT and QML_ELEMENT.

      I have tried to reduce QML and I get the warning even with such simple qml like this (SLModel not used at all):

      import QtQuick
      import programmeguide
      Item {
              id: mainItemId
              anchors.fill: parent
      }
      

      To be honest, I have no idea what is going wrong. Do you have any hint? Thanks!

      J Offline
      J Offline
      JoeCFD
      wrote on 20 Dec 2023, 22:31 last edited by JoeCFD
      #2

      @KejPi said in Warning when creating instantiable object type:

      programmeguide

      There is one example in Qt6 quick/tableview/gameoflife and you may be able to borrow something.
      URI seems different in your cmakefile from the one in this example.

      K 1 Reply Last reply 21 Dec 2023, 09:28
      0
      • J JoeCFD
        20 Dec 2023, 22:31

        @KejPi said in Warning when creating instantiable object type:

        programmeguide

        There is one example in Qt6 quick/tableview/gameoflife and you may be able to borrow something.
        URI seems different in your cmakefile from the one in this example.

        K Offline
        K Offline
        KejPi
        wrote on 21 Dec 2023, 09:28 last edited by KejPi
        #3

        @JoeCFD Thank you for the example hint.
        I have modified my code accordingly but the warning is still there. It turns out that although I get the warning and EPGProxyModel is marked as unknown component (M300) in QtCreator, it seems to work.

        CMake:

        add_executable(${TARGET}
            # ...    
            slmodel.h slmodel.cpp
            epgproxymodel.h epgproxymodel.cpp
        )
        
        qt6_add_qml_module(${TARGET}
            URI ProgrammeGuide
            QML_FILES
                qml/epg.qml
            NO_RESOURCE_TARGET_PATH
            VERSION 1.0
        )
        

        epg.qml

        import QtQuick
        import ProgrammeGuide
        Item {
                id: mainItemId
                anchors.fill: parent
        }
        

        epgdialog.cpp

        // ...
        qmlView->setSource(QUrl("qrc:/qml/epg.qml"));
        // ...
        

        The warning is related to import statement, if I remove import ProgrammeGuide from my minimal example, the warning disappears.

        K 1 Reply Last reply 21 Dec 2023, 09:53
        0
        • K KejPi
          21 Dec 2023, 09:28

          @JoeCFD Thank you for the example hint.
          I have modified my code accordingly but the warning is still there. It turns out that although I get the warning and EPGProxyModel is marked as unknown component (M300) in QtCreator, it seems to work.

          CMake:

          add_executable(${TARGET}
              # ...    
              slmodel.h slmodel.cpp
              epgproxymodel.h epgproxymodel.cpp
          )
          
          qt6_add_qml_module(${TARGET}
              URI ProgrammeGuide
              QML_FILES
                  qml/epg.qml
              NO_RESOURCE_TARGET_PATH
              VERSION 1.0
          )
          

          epg.qml

          import QtQuick
          import ProgrammeGuide
          Item {
                  id: mainItemId
                  anchors.fill: parent
          }
          

          epgdialog.cpp

          // ...
          qmlView->setSource(QUrl("qrc:/qml/epg.qml"));
          // ...
          

          The warning is related to import statement, if I remove import ProgrammeGuide from my minimal example, the warning disappears.

          K Offline
          K Offline
          KejPi
          wrote on 21 Dec 2023, 09:53 last edited by
          #4

          I figured it out finally. Adding these 2 lines before creating QQuickView instance did the trick:

          epgdialog.cpp

              qmlRegisterType<SLModel>("ProgrammeGuide", 1, 0, "SLModel");
              qmlRegisterType<EPGProxyModel>("ProgrammeGuide", 1, 0, "EPGProxyModel");
          

          I am marking the issue as solved.

          1 Reply Last reply
          0
          • K KejPi has marked this topic as solved on 21 Dec 2023, 09:53

          1/4

          20 Dec 2023, 21:07

          • Login

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