diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2024-04-03 12:30:23 +0200 |
---|---|---|
committer | Olivier De Cannière <olivier.decanniere@qt.io> | 2024-04-05 00:42:09 +0200 |
commit | bb6cde5229bd15f6e233262ae46fffeda666cf3d (patch) | |
tree | 78ae0d8207b8e54a51da7e1d85c345f7d8b80cb3 /src/qml/doc | |
parent | d049e07d3ef051175dc83fd9d9b4b7a82dd172f3 (diff) |
Modernize "extending QML" tutorial
- Use qt_standard_project_setup()
- Don't use NO_RESOURCE_TARGET_PATH
- Use QQuickView::loadFromModule()
Pick-to: 6.7
Change-Id: Ie68fbcaaa8824ca1cfe186bc9ead905e705e97c7
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qml/doc')
-rw-r--r-- | src/qml/doc/src/cppintegration/extending-tutorial.qdoc | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/src/qml/doc/src/cppintegration/extending-tutorial.qdoc b/src/qml/doc/src/cppintegration/extending-tutorial.qdoc index 2dc6d0eccc..156ad47089 100644 --- a/src/qml/doc/src/cppintegration/extending-tutorial.qdoc +++ b/src/qml/doc/src/cppintegration/extending-tutorial.qdoc @@ -90,7 +90,7 @@ operations with the QPainter API, we can just subclass QQuickItem. The \c PieChart class defines the two properties, \c name and \c color, with the Q_PROPERTY macro, and overrides QQuickPaintedItem::paint(). The \c PieChart class is registered using the QML_ELEMENT macro, to allow it to be used from -QML. If you don't register the class, \c app.qml won't be able to create a +QML. If you don't register the class, \c App.qml won't be able to create a \c PieChart. \section2 qmake Setup @@ -121,10 +121,10 @@ draw a simple pie chart: \section2 QML Usage Now that we have defined the \c PieChart type, we will use it from QML. The \c -app.qml file creates a \c PieChart item and displays the pie chart's details +App.qml file creates a \c PieChart item and displays the pie chart's details using a standard QML \l Text item: -\snippet tutorials/extending-qml/chapter1-basics/app.qml 0 +\snippet tutorials/extending-qml/chapter1-basics/App.qml 0 Notice that although the color is specified as a string in QML, it is automatically converted to a QColor object for the PieChart \c color property. Automatic conversions are @@ -132,7 +132,7 @@ provided for various other \l {QML Value Types}{value types}. For example, a str like "640x480" can be automatically converted to a QSize value. We'll also create a C++ application that uses a QQuickView to run and -display \c app.qml. +display \c App.qml. Here is the application \c main.cpp: @@ -166,10 +166,10 @@ Now we can build and run the application: \c extending-qml/chapter2-methods Suppose we want \c PieChart to have a "clearChart()" method that erases the -chart and then emits a "chartCleared" signal. Our \c app.qml would be able +chart and then emits a "chartCleared" signal. Our \c App.qml would be able to call \c clearChart() and receive \c chartCleared() signals like this: -\snippet tutorials/extending-qml/chapter2-methods/app.qml 0 +\snippet tutorials/extending-qml/chapter2-methods/App.qml 0 \image extending-tutorial-chapter2.png @@ -213,7 +213,7 @@ other types' values when property values are changed. Let's enable property bindings for the \c color property. That means if we have code like this: -\snippet tutorials/extending-qml/chapter3-bindings/app.qml 0 +\snippet tutorials/extending-qml/chapter3-bindings/App.qml 0 \image extending-tutorial-chapter3.png @@ -295,7 +295,7 @@ For example, let's replace the use of the \c property with a type called "PieSlice" that has a \c color property. Instead of assigning a color, we assign an \c PieSlice value which itself contains a \c color: -\snippet tutorials/extending-qml/chapter4-customPropertyTypes/app.qml 0 +\snippet tutorials/extending-qml/chapter4-customPropertyTypes/App.qml 0 Like \c PieChart, this new \c PieSlice type inherits from QQuickPaintedItem and declares its properties with Q_PROPERTY(): @@ -349,7 +349,7 @@ Right now, a \c PieChart can only have one \c PieSlice. Ideally a chart would have multiple slices, with different colors and sizes. To do this, we could have a \c slices property that accepts a list of \c PieSlice items: -\snippet tutorials/extending-qml/chapter5-listproperties/app.qml 0 +\snippet tutorials/extending-qml/chapter5-listproperties/App.qml 0 \image extending-tutorial-chapter5.png @@ -390,7 +390,7 @@ modification if you have read the previous pages in this tutorial, so the code i \c extending-qml/chapter6-plugins -Currently the \c PieChart and \c PieSlice types are used by \c app.qml, +Currently the \c PieChart and \c PieSlice types are used by \c App.qml, which is displayed using a QQuickView in a C++ application. An alternative way to use our QML extension is to create a plugin library to make it available to the QML engine as a new QML import module. This allows the \c PieChart and @@ -448,12 +448,12 @@ by the module: Now we have a QML module that can be imported to any application, provided that the QML engine knows where to find it. The example contains an executable that loads -\c app.qml, which uses the \c {import Charts 1.0} statement. Alternatively, you can +\c App.qml, which uses the \c {import Charts 1.0} statement. Alternatively, you can load the QML file using the \l {Prototyping with the QML Runtime Tool}{qml tool}, setting the import path to the current directory so that it finds the \c qmldir file: \code - qml -I . app.qml + qml -I . App.qml \endcode The module "Charts" will be loaded by the QML engine, and the types provided by that |