Warning when creating instantiable object type
-
wrote on 20 Dec 2023, 21:07 last edited by
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!
-
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!
wrote on 20 Dec 2023, 22:31 last edited by JoeCFD@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. -
@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.wrote on 21 Dec 2023, 09:28 last edited by KejPi@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 andEPGProxyModel
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. -
@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 andEPGProxyModel
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.wrote on 21 Dec 2023, 09:53 last edited byI 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/4