diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2019-08-21 18:34:21 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2019-09-26 12:32:17 +0200 |
commit | cc1a604c704f848927b3fa0a97b0a50b0b79d2a4 (patch) | |
tree | 610ece713eba021c8e5a3d248f54a62370e810f8 /examples/quick/tableview | |
parent | 531cf90305ae50920b2e597dd0758fdb82ad88b0 (diff) |
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 <fabian.kosmale@qt.io>
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'examples/quick/tableview')
-rw-r--r-- | examples/quick/tableview/gameoflife/gameoflifemodel.h | 2 | ||||
-rw-r--r-- | examples/quick/tableview/gameoflife/main.cpp | 2 | ||||
-rw-r--r-- | examples/quick/tableview/pixelator/imagemodel.h | 2 | ||||
-rw-r--r-- | examples/quick/tableview/pixelator/main.cpp | 2 |
4 files changed, 6 insertions, 2 deletions
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 <array> #include <QAbstractTableModel> #include <QPoint> +#include <QtQml/qqml.h> //! [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>("GameOfLifeModel", 1, 0, "GameOfLifeModel"); + qmlRegisterTypesAndRevisions<GameOfLifeModel>("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 <QAbstractTableModel> #include <QImage> +#include <QtQml/qqml.h> //! [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>("ImageModel", 1, 0, "ImageModel"); + qmlRegisterTypesAndRevisions<ImageModel>("ImageModel", 1); //! [registertype] engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); |