From cc1a604c704f848927b3fa0a97b0a50b0b79d2a4 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Wed, 21 Aug 2019 18:34:21 +0200 Subject: Specify parameters of type registration in class declarations Using this technique we can automatically register all necessary revisions and minor versions of a type, using the metaobject system. This greatly reduces the potential for mistakes and resulting incompatibilities between versions of imports. We assume that for each type we need to register all revisions of its super types and its attached type, and that the revisions match. That is, if you import version X of type A, you will also get version X of its attached type and of any super types. As we previously didn't take these dependencies into account when manually registering the types, a number of extra revisions are now registered for some types. Potentially, we can now generate the qmltypes files at compile time, using moc. Change-Id: I7abb8a5c39f5e63ad1a0cb41a783f2c91909491b Reviewed-by: Fabian Kosmale Reviewed-by: Simon Hausmann --- examples/quick/tableview/gameoflife/gameoflifemodel.h | 2 ++ examples/quick/tableview/gameoflife/main.cpp | 2 +- examples/quick/tableview/pixelator/imagemodel.h | 2 ++ examples/quick/tableview/pixelator/main.cpp | 2 +- 4 files changed, 6 insertions(+), 2 deletions(-) (limited to 'examples/quick/tableview') diff --git a/examples/quick/tableview/gameoflife/gameoflifemodel.h b/examples/quick/tableview/gameoflife/gameoflifemodel.h index 3ea1469861..161e0b2cfc 100644 --- a/examples/quick/tableview/gameoflife/gameoflifemodel.h +++ b/examples/quick/tableview/gameoflife/gameoflifemodel.h @@ -54,11 +54,13 @@ #include #include #include +#include //! [modelclass] class GameOfLifeModel : public QAbstractTableModel { Q_OBJECT + QML_ELEMENT Q_ENUMS(Roles) public: diff --git a/examples/quick/tableview/gameoflife/main.cpp b/examples/quick/tableview/gameoflife/main.cpp index 5101880b06..fcea7080ea 100644 --- a/examples/quick/tableview/gameoflife/main.cpp +++ b/examples/quick/tableview/gameoflife/main.cpp @@ -59,7 +59,7 @@ int main(int argc, char *argv[]) QQmlApplicationEngine engine; //! [registertype] - qmlRegisterType("GameOfLifeModel", 1, 0, "GameOfLifeModel"); + qmlRegisterTypesAndRevisions("GameOfLifeModel", 1); //! [registertype] engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); diff --git a/examples/quick/tableview/pixelator/imagemodel.h b/examples/quick/tableview/pixelator/imagemodel.h index bf0ec90da4..de8ad7cd8d 100644 --- a/examples/quick/tableview/pixelator/imagemodel.h +++ b/examples/quick/tableview/pixelator/imagemodel.h @@ -53,12 +53,14 @@ #include #include +#include //! [model] class ImageModel : public QAbstractTableModel { Q_OBJECT Q_PROPERTY(QString source READ source WRITE setSource NOTIFY sourceChanged) + QML_ELEMENT public: ImageModel(QObject *parent = nullptr); diff --git a/examples/quick/tableview/pixelator/main.cpp b/examples/quick/tableview/pixelator/main.cpp index c57039556a..a8cb6c4e86 100644 --- a/examples/quick/tableview/pixelator/main.cpp +++ b/examples/quick/tableview/pixelator/main.cpp @@ -60,7 +60,7 @@ int main(int argc, char *argv[]) QQmlApplicationEngine engine; //! [registertype] - qmlRegisterType("ImageModel", 1, 0, "ImageModel"); + qmlRegisterTypesAndRevisions("ImageModel", 1); //! [registertype] engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); -- cgit v1.2.3