aboutsummaryrefslogtreecommitdiffstats
path: root/examples/quick/tableview
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2019-09-12 17:03:52 +0200
committerUlf Hermann <ulf.hermann@qt.io>2020-01-13 16:47:57 +0100
commit2c3419e127e55810da1741725b4ff39f118cd577 (patch)
tree670ec93d28dadad06bd840a5694935ef8a7b2ac0 /examples/quick/tableview
parent4eff7299501ff932071300b3fa34fbeccb03d0d8 (diff)
Generate registrations for all examples
Now that we can generate all QML type information at build time, we should also use it. Change-Id: I647c72bbe38fdb2deb565b75c86a696af3d15b61 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'examples/quick/tableview')
-rw-r--r--examples/quick/tableview/gameoflife/doc/src/gameoflife.qdoc6
-rw-r--r--examples/quick/tableview/gameoflife/gameoflife.pro5
-rw-r--r--examples/quick/tableview/gameoflife/main.cpp4
-rw-r--r--examples/quick/tableview/pixelator/doc/src/pixelator.qdoc6
-rw-r--r--examples/quick/tableview/pixelator/main.cpp4
-rw-r--r--examples/quick/tableview/pixelator/pixelator.pro4
6 files changed, 12 insertions, 17 deletions
diff --git a/examples/quick/tableview/gameoflife/doc/src/gameoflife.qdoc b/examples/quick/tableview/gameoflife/doc/src/gameoflife.qdoc
index 069513636a..b61ba90a58 100644
--- a/examples/quick/tableview/gameoflife/doc/src/gameoflife.qdoc
+++ b/examples/quick/tableview/gameoflife/doc/src/gameoflife.qdoc
@@ -50,9 +50,6 @@
the view should be scrolled to.
\snippet tableview/gameoflife/main.qml model
- The model that we use is a custom C++ class that we register
- in the QML system:
- \snippet tableview/gameoflife/main.cpp registertype
\section1 The C++ Model
@@ -61,7 +58,8 @@
used as the model of our TableView component. Therefore, it needs to
implement some functions so the TableView component can interact with
the model. As you can see in the \c private part of the class, the model
- uses a fixed-size array to store the current state of all the cells.
+ uses a fixed-size array to store the current state of all the cells. We
+ also use the QML_ELEMENT macro in order to expose the class to QML.
\snippet tableview/gameoflife/gameoflifemodel.cpp modelsize
Here, the \c rowCount and \c columnCount methods are implemented so
diff --git a/examples/quick/tableview/gameoflife/gameoflife.pro b/examples/quick/tableview/gameoflife/gameoflife.pro
index 98050b0d79..9c47a9b530 100644
--- a/examples/quick/tableview/gameoflife/gameoflife.pro
+++ b/examples/quick/tableview/gameoflife/gameoflife.pro
@@ -1,6 +1,11 @@
TEMPLATE = app
QT += quick qml
+
+CONFIG += qmltypes
+QML_IMPORT_NAME = GameOfLifeModel
+QML_IMPORT_MAJOR_VERSION = 1
+
SOURCES += \
main.cpp \
gameoflifemodel.cpp
diff --git a/examples/quick/tableview/gameoflife/main.cpp b/examples/quick/tableview/gameoflife/main.cpp
index fcea7080ea..1500efdcca 100644
--- a/examples/quick/tableview/gameoflife/main.cpp
+++ b/examples/quick/tableview/gameoflife/main.cpp
@@ -58,10 +58,6 @@ int main(int argc, char *argv[])
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
- //! [registertype]
- qmlRegisterTypesAndRevisions<GameOfLifeModel>("GameOfLifeModel", 1);
- //! [registertype]
-
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
if (engine.rootObjects().isEmpty())
return -1;
diff --git a/examples/quick/tableview/pixelator/doc/src/pixelator.qdoc b/examples/quick/tableview/pixelator/doc/src/pixelator.qdoc
index 9e199a5347..88b28769cd 100644
--- a/examples/quick/tableview/pixelator/doc/src/pixelator.qdoc
+++ b/examples/quick/tableview/pixelator/doc/src/pixelator.qdoc
@@ -42,6 +42,7 @@
TableView.
We use the \l{The Property System}{Qt Property System} and a source property
as \c QString to set the path of the image.
+ We also add the QML_ELEMENT macro to expose the model to QML.
\snippet tableview/pixelator/imagemodel.cpp setsource
@@ -59,11 +60,6 @@
When we call this function with the display role, we return the pixel's
gray value.
- \snippet tableview/pixelator/main.cpp registertype
-
- We need to register our model in the QML type system to be able to use it
- from the QML side.
-
\snippet tableview/pixelator/main.qml pixelcomponent
Each pixel in the \c TableView is displayed via a delegate component.
diff --git a/examples/quick/tableview/pixelator/main.cpp b/examples/quick/tableview/pixelator/main.cpp
index a8cb6c4e86..c07f43dc27 100644
--- a/examples/quick/tableview/pixelator/main.cpp
+++ b/examples/quick/tableview/pixelator/main.cpp
@@ -59,10 +59,6 @@ int main(int argc, char *argv[])
QQmlApplicationEngine engine;
- //! [registertype]
- qmlRegisterTypesAndRevisions<ImageModel>("ImageModel", 1);
- //! [registertype]
-
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
if (engine.rootObjects().isEmpty())
return -1;
diff --git a/examples/quick/tableview/pixelator/pixelator.pro b/examples/quick/tableview/pixelator/pixelator.pro
index 6c863cb304..f27303b56b 100644
--- a/examples/quick/tableview/pixelator/pixelator.pro
+++ b/examples/quick/tableview/pixelator/pixelator.pro
@@ -5,6 +5,10 @@ HEADERS += imagemodel.h
SOURCES += main.cpp \
imagemodel.cpp
+CONFIG += qmltypes
+QML_IMPORT_NAME = ImageModel
+QML_IMPORT_MAJOR_VERSION = 1
+
RESOURCES += qt.png main.qml
target.path = $$[QT_INSTALL_EXAMPLES]/quick/tableview/pixelator