summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlivier De Cannière <olivier.decanniere@qt.io>2023-03-17 15:42:47 +0100
committerOlivier De Cannière <olivier.decanniere@qt.io>2023-03-30 18:02:16 +0200
commit405bd4299819e39397cea0090a9442fd4b6ce911 (patch)
treec1254e18a8ab47cc6bde048eb52ad0d89c2492c8
parent03ff348b4942ae29dd5bc2bd563998d7ba82ecd7 (diff)
downloadqtdeclarative-405bd4299819e39397cea0090a9442fd4b6ce911.tar.gz
Doc: Revamp "Extending QML" examples into a tutorial
The examples in the "Extending QML" series were often redundant with the information of the "Writing QML Extensions with C++" tutorial, had outdated code and sometimes had no documentation. The examples that covered topics not mentioned in the first tutorial were revamped into a second "advanced" tutorial extending the first one. The others were removed. The remaining examples were largely based on the same example code of a birthday party. This code was slightly adapted and separated into 7 states, each building upon the previous, with the code change illustrating the associated feature. A tutorial page, in the style of the first one, was added documenting the different QML features and the required code changes in the example project. Links in the documentation from and to the affected pages were update as best as possible. Pick-to: 6.5 Fixes: QTBUG-111033 Change-Id: I9d97e8b32b128c1624d67525996fa14d493909d3 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
-rw-r--r--examples/README4
-rw-r--r--examples/qml/CMakeLists.txt1
-rw-r--r--examples/qml/doc/src/qml-extending.qdoc339
-rw-r--r--examples/qml/qml.pro1
-rw-r--r--examples/qml/referenceexamples/CMakeLists.txt18
-rw-r--r--examples/qml/referenceexamples/adding/CMakeLists.txt42
-rw-r--r--examples/qml/referenceexamples/adding/adding.pro13
-rw-r--r--examples/qml/referenceexamples/adding/adding.qrc5
-rw-r--r--examples/qml/referenceexamples/adding/example.qml11
-rw-r--r--examples/qml/referenceexamples/adding/main.cpp26
-rw-r--r--examples/qml/referenceexamples/adding/person.cpp27
-rw-r--r--examples/qml/referenceexamples/attached/attached.qrc5
-rw-r--r--examples/qml/referenceexamples/attached/birthdayparty.cpp45
-rw-r--r--examples/qml/referenceexamples/attached/birthdayparty.h57
-rw-r--r--examples/qml/referenceexamples/attached/person.cpp59
-rw-r--r--examples/qml/referenceexamples/binding/CMakeLists.txt45
-rw-r--r--examples/qml/referenceexamples/binding/binding.pro17
-rw-r--r--examples/qml/referenceexamples/binding/binding.qrc5
-rw-r--r--examples/qml/referenceexamples/binding/birthdayparty.cpp66
-rw-r--r--examples/qml/referenceexamples/binding/person.cpp79
-rw-r--r--examples/qml/referenceexamples/coercion/birthdayparty.cpp29
-rw-r--r--examples/qml/referenceexamples/coercion/birthdayparty.h34
-rw-r--r--examples/qml/referenceexamples/coercion/coercion.qrc5
-rw-r--r--examples/qml/referenceexamples/coercion/person.cpp24
-rw-r--r--examples/qml/referenceexamples/default/birthdayparty.cpp30
-rw-r--r--examples/qml/referenceexamples/default/birthdayparty.h35
-rw-r--r--examples/qml/referenceexamples/default/default.qrc5
-rw-r--r--examples/qml/referenceexamples/default/person.cpp24
-rw-r--r--examples/qml/referenceexamples/extended/CMakeLists.txt44
-rw-r--r--examples/qml/referenceexamples/extended/example.qml10
-rw-r--r--examples/qml/referenceexamples/extended/extended.pro13
-rw-r--r--examples/qml/referenceexamples/extended/extended.qrc5
-rw-r--r--examples/qml/referenceexamples/extended/lineedit.cpp71
-rw-r--r--examples/qml/referenceexamples/extended/lineedit.h47
-rw-r--r--examples/qml/referenceexamples/extended/main.cpp27
-rw-r--r--examples/qml/referenceexamples/grouped/birthdayparty.cpp29
-rw-r--r--examples/qml/referenceexamples/grouped/birthdayparty.h34
-rw-r--r--examples/qml/referenceexamples/grouped/grouped.qrc5
-rw-r--r--examples/qml/referenceexamples/grouped/person.cpp59
-rw-r--r--examples/qml/referenceexamples/methods/birthdayparty.cpp39
-rw-r--r--examples/qml/referenceexamples/methods/birthdayparty.h36
-rw-r--r--examples/qml/referenceexamples/methods/example.qml21
-rw-r--r--examples/qml/referenceexamples/methods/methods.qrc5
-rw-r--r--examples/qml/referenceexamples/methods/person.cpp24
-rw-r--r--examples/qml/referenceexamples/methods/person.h30
-rw-r--r--examples/qml/referenceexamples/properties/CMakeLists.txt43
-rw-r--r--examples/qml/referenceexamples/properties/birthdayparty.cpp87
-rw-r--r--examples/qml/referenceexamples/properties/main.cpp28
-rw-r--r--examples/qml/referenceexamples/properties/person.cpp24
-rw-r--r--examples/qml/referenceexamples/properties/person.h30
-rw-r--r--examples/qml/referenceexamples/properties/properties.pro15
-rw-r--r--examples/qml/referenceexamples/properties/properties.qrc5
-rw-r--r--examples/qml/referenceexamples/referenceexamples.pro17
-rw-r--r--examples/qml/referenceexamples/referenceexamples.qmlproject14
-rw-r--r--examples/qml/referenceexamples/signal/CMakeLists.txt44
-rw-r--r--examples/qml/referenceexamples/signal/birthdayparty.cpp51
-rw-r--r--examples/qml/referenceexamples/signal/birthdayparty.h57
-rw-r--r--examples/qml/referenceexamples/signal/example.qml36
-rw-r--r--examples/qml/referenceexamples/signal/main.cpp47
-rw-r--r--examples/qml/referenceexamples/signal/person.cpp59
-rw-r--r--examples/qml/referenceexamples/signal/signal.pro15
-rw-r--r--examples/qml/referenceexamples/signal/signal.qrc5
-rw-r--r--examples/qml/referenceexamples/valuesource/birthdayparty.cpp60
-rw-r--r--examples/qml/referenceexamples/valuesource/person.cpp59
-rw-r--r--examples/qml/referenceexamples/valuesource/person.h77
-rw-r--r--examples/qml/referenceexamples/valuesource/valuesource.qrc5
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/CMakeLists.txt10
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced1-Base-project/CMakeLists.txt (renamed from examples/qml/referenceexamples/methods/CMakeLists.txt)22
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced1-Base-project/Main.qml (renamed from examples/qml/referenceexamples/properties/example.qml)4
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced1-Base-project/baseproject.pro (renamed from examples/qml/referenceexamples/methods/methods.pro)4
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced1-Base-project/baseproject.qrc6
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced1-Base-project/birthdayparty.cpp99
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced1-Base-project/birthdayparty.h (renamed from examples/qml/referenceexamples/properties/birthdayparty.h)24
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced1-Base-project/main.cpp (renamed from examples/qml/referenceexamples/methods/main.cpp)23
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced1-Base-project/person.cpp30
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced1-Base-project/person.h (renamed from examples/qml/referenceexamples/adding/person.h)14
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced1-Base-project/qmldir.in4
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion/CMakeLists.txt (renamed from examples/qml/referenceexamples/coercion/CMakeLists.txt)10
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion/Main.qml (renamed from examples/qml/referenceexamples/coercion/example.qml)4
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion/birthdayparty.cpp99
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion/birthdayparty.h48
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion/coercion.pro (renamed from examples/qml/referenceexamples/coercion/coercion.pro)3
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion/coercion.qrc6
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion/main.cpp (renamed from examples/qml/referenceexamples/coercion/main.cpp)18
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion/person.cpp30
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion/person.h (renamed from examples/qml/referenceexamples/coercion/person.h)19
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion/qmldir.in4
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced3-Default-properties/CMakeLists.txt (renamed from examples/qml/referenceexamples/default/CMakeLists.txt)10
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced3-Default-properties/Main.qml (renamed from examples/qml/referenceexamples/default/example.qml)4
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced3-Default-properties/birthdayparty.cpp99
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced3-Default-properties/birthdayparty.h49
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced3-Default-properties/default.pro (renamed from examples/qml/referenceexamples/default/default.pro)3
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced3-Default-properties/default.qrc6
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced3-Default-properties/main.cpp (renamed from examples/qml/referenceexamples/default/main.cpp)19
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced3-Default-properties/person.cpp30
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced3-Default-properties/person.h (renamed from examples/qml/referenceexamples/default/person.h)16
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced3-Default-properties/qmldir.in4
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced4-Grouped-properties/CMakeLists.txt (renamed from examples/qml/referenceexamples/grouped/CMakeLists.txt)16
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced4-Grouped-properties/Main.qml (renamed from examples/qml/referenceexamples/grouped/example.qml)12
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced4-Grouped-properties/birthdayparty.cpp99
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced4-Grouped-properties/birthdayparty.h49
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced4-Grouped-properties/grouped.pro (renamed from examples/qml/referenceexamples/grouped/grouped.pro)3
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced4-Grouped-properties/grouped.qrc6
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced4-Grouped-properties/main.cpp (renamed from examples/qml/referenceexamples/grouped/main.cpp)19
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced4-Grouped-properties/person.cpp87
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced4-Grouped-properties/person.h (renamed from examples/qml/referenceexamples/binding/person.h)31
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced4-Grouped-properties/qmldir.in5
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties/CMakeLists.txt (renamed from examples/qml/referenceexamples/attached/CMakeLists.txt)16
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties/Main.qml (renamed from examples/qml/referenceexamples/attached/example.qml)19
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties/attached.pro (renamed from examples/qml/referenceexamples/attached/attached.pro)7
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties/attached.qrc6
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties/birthdayparty.cpp117
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties/birthdayparty.h (renamed from examples/qml/referenceexamples/binding/birthdayparty.h)35
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties/main.cpp (renamed from examples/qml/referenceexamples/attached/main.cpp)20
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties/person.cpp87
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties/person.h (renamed from examples/qml/referenceexamples/attached/person.h)36
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties/qmldir.in5
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/CMakeLists.txt (renamed from examples/qml/referenceexamples/valuesource/CMakeLists.txt)16
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/Main.qml (renamed from examples/qml/referenceexamples/valuesource/example.qml)18
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/birthdayparty.cpp137
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/birthdayparty.h (renamed from examples/qml/referenceexamples/valuesource/birthdayparty.h)44
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/happybirthdaysong.cpp (renamed from examples/qml/referenceexamples/binding/happybirthdaysong.cpp)22
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/happybirthdaysong.h (renamed from examples/qml/referenceexamples/binding/happybirthdaysong.h)15
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/main.cpp (renamed from examples/qml/referenceexamples/valuesource/main.cpp)23
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/person.cpp87
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/person.h (renamed from examples/qml/referenceexamples/signal/person.h)36
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/qmldir.in5
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/valuesource.pro (renamed from examples/qml/referenceexamples/valuesource/valuesource.pro)5
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/valuesource.qrc6
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/CMakeLists.txt60
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/Main.qml (renamed from examples/qml/referenceexamples/binding/example.qml)28
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/application.pro26
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/birthdayparty.cpp150
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/birthdayparty.h90
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/foreign.pro7
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/foreign.qrc6
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/foreigndisplay.h20
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/happybirthdaysong.cpp (renamed from examples/qml/referenceexamples/valuesource/happybirthdaysong.cpp)16
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/happybirthdaysong.h (renamed from examples/qml/referenceexamples/valuesource/happybirthdaysong.h)15
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/library/CMakeLists.txt17
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/library/ThirdPartyDisplay.cpp45
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/library/ThirdPartyDisplay.h36
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/library/library.pro8
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/main.cpp (renamed from examples/qml/referenceexamples/binding/main.cpp)20
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/person.cpp87
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/person.h (renamed from examples/qml/referenceexamples/grouped/person.h)36
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/qmldir.in5
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/extending-qml-advanced.pro10
-rw-r--r--src/qml/doc/images/extending-qml-advanced-word-cloud.pngbin0 -> 73771 bytes
-rw-r--r--src/qml/doc/src/cppintegration/definetypes.qdoc9
-rw-r--r--src/qml/doc/src/cppintegration/extending-tutorial-advanced.qdoc380
-rw-r--r--src/qml/doc/src/cppintegration/extending-tutorial.qdoc7
-rw-r--r--src/qml/doc/src/examples.qdoc47
-rw-r--r--src/qml/doc/src/qmlfunctions.qdoc2
-rw-r--r--src/qml/doc/src/qtqml.qdoc4
-rw-r--r--src/qml/qml/qqmllist.cpp2
-rw-r--r--src/quick/doc/src/examples.qdoc11
-rw-r--r--tests/auto/guiapplauncher/examples.txt11
158 files changed, 2561 insertions, 2732 deletions
diff --git a/examples/README b/examples/README
index f4567ab1d2..a8ec653023 100644
--- a/examples/README
+++ b/examples/README
@@ -6,8 +6,8 @@ designers to actually implement their UI vision. QML UIs can integrate
with C++ code in many ways, including being loaded as a part of a C++ UI
and loading data models from C++ and interacting with them.
-Mostof these examples can be viewed directly with the
+Most of these examples can be viewed directly with the
QML viewer utility, without requiring compilation.
-Documentation for these examples can be found via the Examples
+Documentation for these examples can be found via the Examples and Tutorials
link in the main Qt documentation.
diff --git a/examples/qml/CMakeLists.txt b/examples/qml/CMakeLists.txt
index 6b3e51bf9f..3d2cbc4503 100644
--- a/examples/qml/CMakeLists.txt
+++ b/examples/qml/CMakeLists.txt
@@ -1,7 +1,6 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
-add_subdirectory(referenceexamples)
add_subdirectory(tutorials)
if(TARGET Qt::Quick)
qt_internal_add_example(qmlextensionplugins)
diff --git a/examples/qml/doc/src/qml-extending.qdoc b/examples/qml/doc/src/qml-extending.qdoc
deleted file mode 100644
index 5d92f0a51c..0000000000
--- a/examples/qml/doc/src/qml-extending.qdoc
+++ /dev/null
@@ -1,339 +0,0 @@
-// Copyright (C) 2017 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
-
-/*!
-\example referenceexamples/adding
-\title Extending QML - Adding Types Example
-\brief Exporting C++ Classes.
-\ingroup qmlextendingexamples
-
-The Adding Types Example shows how to add a new object type, \c Person, to QML.
-The \c Person type can be used from QML like this:
-
-\snippet referenceexamples/adding/example.qml 0
-
-\section1 Declare the Person Class
-
-All QML types map to C++ types. Here we declare a basic C++ Person class
-with the two properties we want accessible on the QML type - name and shoeSize.
-Although in this example we use the same name for the C++ class as the QML
-type, the C++ class can be named differently, or appear in a namespace.
-
-\snippet referenceexamples/adding/person.h 0
-
-\section1 Define the Person Class
-
-\snippet referenceexamples/adding/person.cpp 0
-
-The Person class implementation is quite basic. The property accessors simply
-return members of the object instance.
-
-\section1 Running the Example
-
-The main.cpp file in the example includes a simple shell application that
-loads and runs the QML snippet shown at the beginning of this page.
-*/
-
-/*!
-\example referenceexamples/extended
-\title Extending QML - Extension Objects Example
-\brief Extension Objects.
-\ingroup qmlextendingexamples
-
-This example builds on:
-\list
-\li \l {Extending QML - Adding Types Example}
-\endlist
-
-Shows how to use \l {QML_EXTENDED} to provide an
-\l {Registering Extension Objects}{extension object} to a \l QLineEdit without modifying or
-subclassing it.
-
-Firstly, the LineEditExtension class is registered with the QML system as an
-extension of QLineEdit. We declare a foreign type to do this as we cannot modify
-Qt's internal QLineEdit class.
-
-\snippet referenceexamples/extended/lineedit.h 0
-
-Note the usage of \l QML_NAMED_ELEMENT() instead of \l QML_ELEMENT.
-QML_ELEMENT uses the name of the containing type by default, "LineEditExtension" in this case.
-As the class being an extension class is an implementation detail, we choose the more natural name "LineEdit" instead
-
-The QML engine then instantiates a \l QLineEdit:
-
-\snippet referenceexamples/extended/main.cpp 1
-
-In QML, a property is set on the line edit that only exists in the LineEditExtension class:
-
-\snippet referenceexamples/extended/example.qml 0
-
-The extension type performs calls on the \l QLineEdit that otherwise will
-not be accessible to the QML engine.
-*/
-
-/*!
-\example referenceexamples/properties
-\title Extending QML - Object and List Property Types Example
-\brief Exporting C++ Properties.
-\ingroup qmlextendingexamples
-
-This example builds on:
-\list
-\li \l {Extending QML - Adding Types Example}
-\endlist
-
-The Object and List Property Types example shows how to add object and list
-properties in QML. This example adds a BirthdayParty type that specifies
-a birthday party, consisting of a celebrant and a list of guests. People are
-specified using the People QML type built in the previous example.
-
-\snippet referenceexamples/properties/example.qml 0
-
-\section1 Declare the BirthdayParty
-
-The BirthdayParty class is declared like this:
-
-\snippet referenceexamples/properties/birthdayparty.h 0
-\snippet referenceexamples/properties/birthdayparty.h 1
-\snippet referenceexamples/properties/birthdayparty.h 2
-\snippet referenceexamples/properties/birthdayparty.h 3
-
-The class contains a member to store the celebrant object, and also a
-QList<Person *> member.
-
-In QML, the type of a list properties - and the guests property is a list of
-people - are all of type QQmlListProperty<T>. QQmlListProperty is simple value
-type that contains a set of function pointers. QML calls these function
-pointers whenever it needs to read from, write to or otherwise interact with
-the list. In addition to concrete lists like the people list used in this
-example, the use of QQmlListProperty allows for "virtual lists" and other advanced
-scenarios.
-
-\section2 Define the BirthdayParty
-
-The implementation of BirthdayParty property accessors is straight forward.
-
-\snippet referenceexamples/properties/birthdayparty.cpp 0
-
-\section1 Running the Example
-
-The main.cpp file in the example includes a simple shell application that
-loads and runs the QML snippet shown at the beginning of this page.
-*/
-
-/*!
-\example referenceexamples/coercion
-\title Extending QML - Inheritance and Coercion Example
-\brief C++ Inheritance and Coercion.
-\ingroup qmlextendingexamples
-
-This example builds on:
-\list
-\li \l {Extending QML - Object and List Property Types Example}
-\li \l {Extending QML - Adding Types Example}
-\endlist
-
-The Inheritance and Coercion Example shows how to use base classes to assign
-types of more than one type to a property. It specializes the Person type
-developed in the previous examples into two types - a \c Boy and a \c Girl.
-
-\snippet referenceexamples/coercion/example.qml 0
-
-\section1 Declare Boy and Girl
-
-\snippet referenceexamples/coercion/person.h 1
-
-The Person class remains unaltered in this example and the Boy and Girl C++
-classes are trivial extensions of it. The types and their QML name are
-registered with the QML engine.
-
-As an example, the inheritance used here is a little contrived, but in real
-applications it is likely that the two extensions would add additional
-properties or modify the Person classes behavior.
-
-\section2 Define People as a Base Class
-
-The implementation of the People class itself has not changed since the
-previous example. However, as we have repurposed the People class as a common
-base for Boy and Girl, we want to prevent it from being instantiated from QML
-directly - an explicit Boy or Girl should be instantiated instead.
-
-\snippet referenceexamples/coercion/person.h 0
-
-While we want to disallow instantiating Person from within QML, it still needs
-to be registered with the QML engine, so that it can be used as a property type
-and other types can be coerced to it. This is what the QML_UNCREATABLE macro
-does.
-
-\section1 Running the Example
-
-The BirthdayParty type has not changed since the previous example. The
-celebrant and guests property still use the People type.
-
-\snippet referenceexamples/coercion/birthdayparty.h 0
-
-However, as all three types, Person, Boy and Girl, have been registered with the
-QML system, on assignment QML automatically (and type-safely) converts the Boy
-and Girl objects into a Person.
-
-The main.cpp file in the example includes a simple shell application that
-loads and runs the QML snippet shown at the beginning of this page.
-*/
-
-/*!
-\example referenceexamples/default
-\title Extending QML - Default Property Example
-\brief Default Property.
-\ingroup qmlextendingexamples
-
-This example builds on:
-\list
-\li \l {Extending QML - Inheritance and Coercion Example}
-\li \l {Extending QML - Object and List Property Types Example}
-\li \l {Extending QML - Adding Types Example}
-\endlist
-
-The Default Property Example is a minor modification of the
-\l {Extending QML - Inheritance and Coercion Example} that simplifies the
-specification of a BirthdayParty through the use of a default property.
-
-\snippet referenceexamples/default/example.qml 0
-
-\section1 Declaring the BirthdayParty Class
-
-The only difference between this example and the last, is the addition of the
-\c DefaultProperty class info annotation.
-
-\snippet referenceexamples/default/birthdayparty.h 0
-
-The default property specifies the property to assign to whenever an explicit
-property is not specified, in the case of the BirthdayParty type the guest
-property. It is purely a syntactic simplification, the behavior is identical
-to specifying the property by name, but it can add a more natural feel in many
-situations. The default property must be either an object or list property.
-
-\section1 Running the Example
-
-The main.cpp file in the example includes a simple shell application that
-loads and runs the QML snippet shown at the beginning of this page.
-*/
-
-/*!
-\example referenceexamples/grouped
-\title Extending QML - Grouped Properties Example
-\brief Grouped Properties.
-\ingroup qmlextendingexamples
-
-This example builds on:
-\list
-\li \l {Extending QML - Default Property Example}
-\li \l {Extending QML - Inheritance and Coercion Example}
-\li \l {Extending QML - Object and List Property Types Example}
-\li \l {Extending QML - Adding Types Example}
-\endlist
-
-*/
-
-/*!
-\example referenceexamples/attached
-\title Extending QML - Attached Properties Example
-\brief Attached Properties.
-\ingroup qmlextendingexamples
-
-This example demonstrates how to create custom
-\l {Attached Properties and Attached Signal Handlers} {attached properties}.
-For a more in-depth description on how one can create attached properties,
-see \l {Providing Attached Properties}.
-
-
-This example builds on:
-\list
-\li \l {Extending QML - Grouped Properties Example}
-\li \l {Extending QML - Default Property Example}
-\li \l {Extending QML - Inheritance and Coercion Example}
-\li \l {Extending QML - Object and List Property Types Example}
-\li \l {Extending QML - Adding Types Example}
-\endlist
-
-*/
-
-/*!
-\example referenceexamples/signal
-\title Extending QML - Signal Support Example
-\brief Signal Support.
-\ingroup qmlextendingexamples
-
-This example builds on:
-\list
-\li \l {Extending QML - Attached Properties Example}
-\li \l {Extending QML - Grouped Properties Example}
-\li \l {Extending QML - Default Property Example}
-\li \l {Extending QML - Inheritance and Coercion Example}
-\li \l {Extending QML - Object and List Property Types Example}
-\li \l {Extending QML - Adding Types Example}
-\endlist
-
-*/
-
-/*!
-\example referenceexamples/methods
-\title Extending QML - Methods Example
-\brief Methods Support.
-\ingroup qmlextendingexamples
-
-This example builds on:
-\list
-\li \l {Extending QML - Inheritance and Coercion Example}
-\li \l {Extending QML - Object and List Property Types Example}
-\li \l {Extending QML - Adding Types Example}
-\endlist
-
-The Methods Example has an additional method in the \c BirthdayParty class: \c invite().
-\c invite() is declared with \l Q_INVOKABLE so that it can be
-called from QML.
-
-\snippet referenceexamples/methods/birthdayparty.h 0
-
-In \c example.qml, the \c invite() method is called in the \l [QML]{QtQml::Component::completed()}{Component.onCompleted} signal handler:
-
-\snippet referenceexamples/methods/example.qml 0
-*/
-
-/*!
-\example referenceexamples/valuesource
-\title Extending QML - Property Value Source Example
-\brief Property Value Source.
-\ingroup qmlextendingexamples
-
-This example builds on:
-\list
-\li \l {Extending QML - Signal Support Example}
-\li \l {Extending QML - Attached Properties Example}
-\li \l {Extending QML - Grouped Properties Example}
-\li \l {Extending QML - Default Property Example}
-\li \l {Extending QML - Inheritance and Coercion Example}
-\li \l {Extending QML - Object and List Property Types Example}
-\li \l {Extending QML - Adding Types Example}
-\endlist
-
-*/
-
-/*!
-\example referenceexamples/binding
-\title Extending QML - Binding Example
-\brief Binding.
-\ingroup qmlextendingexamples
-
-This example builds on:
-\list
-\li \l {Extending QML - Property Value Source Example}
-\li \l {Extending QML - Signal Support Example}
-\li \l {Extending QML - Attached Properties Example}
-\li \l {Extending QML - Grouped Properties Example}
-\li \l {Extending QML - Default Property Example}
-\li \l {Extending QML - Inheritance and Coercion Example}
-\li \l {Extending QML - Object and List Property Types Example}
-\li \l {Extending QML - Adding Types Example}
-\endlist
-
-*/
diff --git a/examples/qml/qml.pro b/examples/qml/qml.pro
index 9fe8aab7e0..b59620cb81 100644
--- a/examples/qml/qml.pro
+++ b/examples/qml/qml.pro
@@ -7,7 +7,6 @@ qtHaveModule(quick) {
}
SUBDIRS += \
- referenceexamples \
tutorials
EXAMPLE_FILES = \
diff --git a/examples/qml/referenceexamples/CMakeLists.txt b/examples/qml/referenceexamples/CMakeLists.txt
deleted file mode 100644
index 88908ec9a0..0000000000
--- a/examples/qml/referenceexamples/CMakeLists.txt
+++ /dev/null
@@ -1,18 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-qt_internal_add_example(adding)
-qt_internal_add_example(coercion)
-qt_internal_add_example(default)
-qt_internal_add_example(properties)
-qt_internal_add_example(methods)
-if(TARGET Qt::Widgets)
- qt_internal_add_example(extended)
-endif()
-if(TARGET Qt::Quick)
- qt_internal_add_example(attached)
- qt_internal_add_example(binding)
- qt_internal_add_example(grouped)
- qt_internal_add_example(signal)
- qt_internal_add_example(valuesource)
-endif()
diff --git a/examples/qml/referenceexamples/adding/CMakeLists.txt b/examples/qml/referenceexamples/adding/CMakeLists.txt
deleted file mode 100644
index f1d3fc6eac..0000000000
--- a/examples/qml/referenceexamples/adding/CMakeLists.txt
+++ /dev/null
@@ -1,42 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(adding LANGUAGES CXX)
-
-set(CMAKE_AUTOMOC ON)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/qml/referenceexamples/adding")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Qml)
-
-qt_add_executable(adding
- main.cpp
- person.cpp person.h
-)
-
-set_target_properties(adding PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(adding PUBLIC
- Qt::Core
- Qt::Qml
-)
-
-qt_add_qml_module(adding
- URI People
- QML_FILES example.qml
- NO_RESOURCE_TARGET_PATH
-)
-
-install(TARGETS adding
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/qml/referenceexamples/adding/adding.pro b/examples/qml/referenceexamples/adding/adding.pro
deleted file mode 100644
index a4a677c3c4..0000000000
--- a/examples/qml/referenceexamples/adding/adding.pro
+++ /dev/null
@@ -1,13 +0,0 @@
-QT = core qml
-CONFIG += qmltypes
-
-QML_IMPORT_NAME = People
-QML_IMPORT_MAJOR_VERSION = 1
-
-SOURCES += main.cpp \
- person.cpp
-HEADERS += person.h
-RESOURCES += adding.qrc
-
-target.path = $$[QT_INSTALL_EXAMPLES]/qml/referenceexamples/adding
-INSTALLS += target
diff --git a/examples/qml/referenceexamples/adding/adding.qrc b/examples/qml/referenceexamples/adding/adding.qrc
deleted file mode 100644
index e2fa01d5e7..0000000000
--- a/examples/qml/referenceexamples/adding/adding.qrc
+++ /dev/null
@@ -1,5 +0,0 @@
-<!DOCTYPE RCC><RCC version="1.0">
-<qresource>
- <file>example.qml</file>
-</qresource>
-</RCC>
diff --git a/examples/qml/referenceexamples/adding/example.qml b/examples/qml/referenceexamples/adding/example.qml
deleted file mode 100644
index 068352bc35..0000000000
--- a/examples/qml/referenceexamples/adding/example.qml
+++ /dev/null
@@ -1,11 +0,0 @@
-// Copyright (C) 2017 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-// ![0]
-import People
-
-Person {
- name: "Bob Jones"
- shoeSize: 12
-}
-// ![0]
diff --git a/examples/qml/referenceexamples/adding/main.cpp b/examples/qml/referenceexamples/adding/main.cpp
deleted file mode 100644
index 319217da56..0000000000
--- a/examples/qml/referenceexamples/adding/main.cpp
+++ /dev/null
@@ -1,26 +0,0 @@
-// Copyright (C) 2021 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include <QCoreApplication>
-#include <QQmlEngine>
-#include <QQmlComponent>
-#include <QDebug>
-#include "person.h"
-
-int main(int argc, char ** argv)
-{
- QCoreApplication app(argc, argv);
-
- QQmlEngine engine;
- QQmlComponent component(&engine, QUrl("qrc:example.qml"));
- auto *person = qobject_cast<Person *>(component.create());
- if (!person) {
- qWarning() << component.errors();
- return EXIT_FAILURE;
- }
-
- qInfo() << "The person's name is" << person->name()
- << "\nThey wear a" << person->shoeSize() << "sized shoe";
-
- return EXIT_SUCCESS;
-}
diff --git a/examples/qml/referenceexamples/adding/person.cpp b/examples/qml/referenceexamples/adding/person.cpp
deleted file mode 100644
index 5b6ce4b9d6..0000000000
--- a/examples/qml/referenceexamples/adding/person.cpp
+++ /dev/null
@@ -1,27 +0,0 @@
-// Copyright (C) 2021 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "person.h"
-
-// ![0]
-QString Person::name() const
-{
- return m_name;
-}
-
-void Person::setName(const QString &n)
-{
- m_name = n;
-}
-
-int Person::shoeSize() const
-{
- return m_shoeSize;
-}
-
-void Person::setShoeSize(int s)
-{
- m_shoeSize = s;
-}
-
-// ![0]
diff --git a/examples/qml/referenceexamples/attached/attached.qrc b/examples/qml/referenceexamples/attached/attached.qrc
deleted file mode 100644
index e2fa01d5e7..0000000000
--- a/examples/qml/referenceexamples/attached/attached.qrc
+++ /dev/null
@@ -1,5 +0,0 @@
-<!DOCTYPE RCC><RCC version="1.0">
-<qresource>
- <file>example.qml</file>
-</qresource>
-</RCC>
diff --git a/examples/qml/referenceexamples/attached/birthdayparty.cpp b/examples/qml/referenceexamples/attached/birthdayparty.cpp
deleted file mode 100644
index a76b0f55cb..0000000000
--- a/examples/qml/referenceexamples/attached/birthdayparty.cpp
+++ /dev/null
@@ -1,45 +0,0 @@
-// Copyright (C) 2021 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "birthdayparty.h"
-
-QDate BirthdayPartyAttached::rsvp() const
-{
- return m_rsvp;
-}
-
-void BirthdayPartyAttached::setRsvp(QDate d)
-{
- m_rsvp = d;
-}
-
-Person *BirthdayParty::host() const
-{
- return m_host;
-}
-
-void BirthdayParty::setHost(Person *c)
-{
- m_host = c;
-}
-
-QQmlListProperty<Person> BirthdayParty::guests()
-{
- return {this, &m_guests};
-}
-
-qsizetype BirthdayParty::guestCount() const
-{
- return m_guests.count();
-}
-
-Person *BirthdayParty::guest(qsizetype index) const
-{
- return m_guests.at(index);
-}
-
-BirthdayPartyAttached *BirthdayParty::qmlAttachedProperties(QObject *object)
-{
- return new BirthdayPartyAttached(object);
-}
-
diff --git a/examples/qml/referenceexamples/attached/birthdayparty.h b/examples/qml/referenceexamples/attached/birthdayparty.h
deleted file mode 100644
index 7eb6508869..0000000000
--- a/examples/qml/referenceexamples/attached/birthdayparty.h
+++ /dev/null
@@ -1,57 +0,0 @@
-// Copyright (C) 2021 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef BIRTHDAYPARTY_H
-#define BIRTHDAYPARTY_H
-
-#include <QObject>
-#include <QDate>
-#include <qqml.h>
-#include "person.h"
-
-class BirthdayPartyAttached : public QObject
-{
- Q_OBJECT
- Q_PROPERTY(QDate rsvp READ rsvp WRITE setRsvp)
- QML_ANONYMOUS
-public:
- using QObject::QObject;
-
- QDate rsvp() const;
- void setRsvp(QDate);
-
-private:
- QDate m_rsvp;
-};
-
-class BirthdayParty : public QObject
-{
- Q_OBJECT
- Q_PROPERTY(Person *host READ host WRITE setHost)
- Q_PROPERTY(QQmlListProperty<Person> guests READ guests)
- Q_CLASSINFO("DefaultProperty", "guests")
- QML_ELEMENT
-
-//! [declare attached]
- QML_ATTACHED(BirthdayPartyAttached)
-//! [declare attached]
-
-public:
- using QObject::QObject;
-
- Person *host() const;
- void setHost(Person *);
-
- QQmlListProperty<Person> guests();
- qsizetype guestCount() const;
- Person *guest(qsizetype) const;
-
- //! [static attached]
- static BirthdayPartyAttached *qmlAttachedProperties(QObject *);
- //! [static attached]
-private:
- Person *m_host = nullptr;
- QList<Person *> m_guests;
-};
-
-#endif // BIRTHDAYPARTY_H
diff --git a/examples/qml/referenceexamples/attached/person.cpp b/examples/qml/referenceexamples/attached/person.cpp
deleted file mode 100644
index 358fbf0ed8..0000000000
--- a/examples/qml/referenceexamples/attached/person.cpp
+++ /dev/null
@@ -1,59 +0,0 @@
-// Copyright (C) 2021 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "person.h"
-
-int ShoeDescription::size() const
-{
- return m_size;
-}
-
-void ShoeDescription::setSize(int s)
-{
- m_size = s;
-}
-
-QColor ShoeDescription::color() const
-{
- return m_color;
-}
-
-void ShoeDescription::setColor(const QColor &c)
-{
- m_color = c;
-}
-
-QString ShoeDescription::brand() const
-{
- return m_brand;
-}
-
-void ShoeDescription::setBrand(const QString &b)
-{
- m_brand = b;
-}
-
-qreal ShoeDescription::price() const
-{
- return m_price;
-}
-
-void ShoeDescription::setPrice(qreal p)
-{
- m_price = p;
-}
-
-QString Person::name() const
-{
- return m_name;
-}
-
-void Person::setName(const QString &n)
-{
- m_name = n;
-}
-
-ShoeDescription *Person::shoe()
-{
- return &m_shoe;
-}
diff --git a/examples/qml/referenceexamples/binding/CMakeLists.txt b/examples/qml/referenceexamples/binding/CMakeLists.txt
deleted file mode 100644
index 83ad8001e8..0000000000
--- a/examples/qml/referenceexamples/binding/CMakeLists.txt
+++ /dev/null
@@ -1,45 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(binding LANGUAGES CXX)
-
-set(CMAKE_AUTOMOC ON)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/qml/referenceexamples/binding")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Gui Qml)
-
-qt_add_executable(binding
- birthdayparty.cpp birthdayparty.h
- happybirthdaysong.cpp happybirthdaysong.h
- main.cpp
- person.cpp person.h
-)
-
-set_target_properties(binding PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(binding PUBLIC
- Qt::Core
- Qt::Gui
- Qt::Qml
-)
-
-qt_add_qml_module(binding
- URI People
- QML_FILES example.qml
- NO_RESOURCE_TARGET_PATH
-)
-
-install(TARGETS binding
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/qml/referenceexamples/binding/binding.pro b/examples/qml/referenceexamples/binding/binding.pro
deleted file mode 100644
index dce780d0a2..0000000000
--- a/examples/qml/referenceexamples/binding/binding.pro
+++ /dev/null
@@ -1,17 +0,0 @@
-QT += qml
-
-CONFIG += qmltypes
-QML_IMPORT_NAME = People
-QML_IMPORT_MAJOR_VERSION = 1
-
-SOURCES += main.cpp \
- person.cpp \
- birthdayparty.cpp \
- happybirthdaysong.cpp
-HEADERS += person.h \
- birthdayparty.h \
- happybirthdaysong.h
-RESOURCES += binding.qrc
-
-target.path = $$[QT_INSTALL_EXAMPLES]/qml/referenceexamples/binding
-INSTALLS += target
diff --git a/examples/qml/referenceexamples/binding/binding.qrc b/examples/qml/referenceexamples/binding/binding.qrc
deleted file mode 100644
index e2fa01d5e7..0000000000
--- a/examples/qml/referenceexamples/binding/binding.qrc
+++ /dev/null
@@ -1,5 +0,0 @@
-<!DOCTYPE RCC><RCC version="1.0">
-<qresource>
- <file>example.qml</file>
-</qresource>
-</RCC>
diff --git a/examples/qml/referenceexamples/binding/birthdayparty.cpp b/examples/qml/referenceexamples/binding/birthdayparty.cpp
deleted file mode 100644
index a98b5fbdfb..0000000000
--- a/examples/qml/referenceexamples/binding/birthdayparty.cpp
+++ /dev/null
@@ -1,66 +0,0 @@
-// Copyright (C) 2021 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "birthdayparty.h"
-
-QDate BirthdayPartyAttached::rsvp() const
-{
- return m_rsvp;
-}
-
-void BirthdayPartyAttached::setRsvp(QDate d)
-{
- if (d != m_rsvp) {
- m_rsvp = d;
- emit rsvpChanged();
- }
-}
-
-Person *BirthdayParty::host() const
-{
- return m_host;
-}
-
-void BirthdayParty::setHost(Person *c)
-{
- if (c == m_host) return;
- m_host = c;
- emit hostChanged();
-}
-
-QQmlListProperty<Person> BirthdayParty::guests()
-{
- return QQmlListProperty<Person>(this, &m_guests);
-}
-
-qsizetype BirthdayParty::guestCount() const
-{
- return m_guests.count();
-}
-
-Person *BirthdayParty::guest(qsizetype index) const
-{
- return m_guests.at(index);
-}
-
-void BirthdayParty::startParty()
-{
- QTime time = QTime::currentTime();
- emit partyStarted(time);
-}
-
-QString BirthdayParty::announcement() const
-{
- return QString();
-}
-
-void BirthdayParty::setAnnouncement(const QString &speak)
-{
- qWarning().noquote() << speak;
-}
-
-BirthdayPartyAttached *BirthdayParty::qmlAttachedProperties(QObject *object)
-{
- return new BirthdayPartyAttached(object);
-}
-
diff --git a/examples/qml/referenceexamples/binding/person.cpp b/examples/qml/referenceexamples/binding/person.cpp
deleted file mode 100644
index a4c26679d6..0000000000
--- a/examples/qml/referenceexamples/binding/person.cpp
+++ /dev/null
@@ -1,79 +0,0 @@
-// Copyright (C) 2021 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "person.h"
-
-int ShoeDescription::size() const
-{
- return m_size;
-}
-
-void ShoeDescription::setSize(int s)
-{
- if (m_size == s)
- return;
-
- m_size = s;
- emit shoeChanged();
-}
-
-QColor ShoeDescription::color() const
-{
- return m_color;
-}
-
-void ShoeDescription::setColor(const QColor &c)
-{
- if (m_color == c)
- return;
-
- m_color = c;
- emit shoeChanged();
-}
-
-QString ShoeDescription::brand() const
-{
- return m_brand;
-}
-
-void ShoeDescription::setBrand(const QString &b)
-{
- if (m_brand == b)
- return;
-
- m_brand = b;
- emit shoeChanged();
-}
-
-qreal ShoeDescription::price() const
-{
- return m_price;
-}
-
-void ShoeDescription::setPrice(qreal p)
-{
- if (m_price == p)
- return;
-
- m_price = p;
- emit shoeChanged();
-}
-
-QString Person::name() const
-{
- return m_name;
-}
-
-void Person::setName(const QString &n)
-{
- if (m_name == n)
- return;
-
- m_name = n;
- emit nameChanged();
-}
-
-ShoeDescription *Person::shoe()
-{
- return &m_shoe;
-}
diff --git a/examples/qml/referenceexamples/coercion/birthdayparty.cpp b/examples/qml/referenceexamples/coercion/birthdayparty.cpp
deleted file mode 100644
index 6cf8a608e7..0000000000
--- a/examples/qml/referenceexamples/coercion/birthdayparty.cpp
+++ /dev/null
@@ -1,29 +0,0 @@
-// Copyright (C) 2021 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "birthdayparty.h"
-
-Person *BirthdayParty::host() const
-{
- return m_host;
-}
-
-void BirthdayParty::setHost(Person *c)
-{
- m_host = c;
-}
-
-QQmlListProperty<Person> BirthdayParty::guests()
-{
- return {this, &m_guests};
-}
-
-qsizetype BirthdayParty::guestCount() const
-{
- return m_guests.count();
-}
-
-Person *BirthdayParty::guest(qsizetype index) const
-{
- return m_guests.at(index);
-}
diff --git a/examples/qml/referenceexamples/coercion/birthdayparty.h b/examples/qml/referenceexamples/coercion/birthdayparty.h
deleted file mode 100644
index 79508ff9c1..0000000000
--- a/examples/qml/referenceexamples/coercion/birthdayparty.h
+++ /dev/null
@@ -1,34 +0,0 @@
-// Copyright (C) 2021 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef BIRTHDAYPARTY_H
-#define BIRTHDAYPARTY_H
-
-#include <QObject>
-#include <QQmlListProperty>
-#include "person.h"
-
-class BirthdayParty : public QObject
-{
- Q_OBJECT
-// ![0]
- Q_PROPERTY(Person *host READ host WRITE setHost)
- Q_PROPERTY(QQmlListProperty<Person> guests READ guests)
- QML_ELEMENT
-// ![0]
-public:
- using QObject::QObject;
-
- Person *host() const;
- void setHost(Person *);
-
- QQmlListProperty<Person> guests();
- qsizetype guestCount() const;
- Person *guest(qsizetype) const;
-
-private:
- Person *m_host = nullptr;
- QList<Person *> m_guests;
-};
-
-#endif // BIRTHDAYPARTY_H
diff --git a/examples/qml/referenceexamples/coercion/coercion.qrc b/examples/qml/referenceexamples/coercion/coercion.qrc
deleted file mode 100644
index e2fa01d5e7..0000000000
--- a/examples/qml/referenceexamples/coercion/coercion.qrc
+++ /dev/null
@@ -1,5 +0,0 @@
-<!DOCTYPE RCC><RCC version="1.0">
-<qresource>
- <file>example.qml</file>
-</qresource>
-</RCC>
diff --git a/examples/qml/referenceexamples/coercion/person.cpp b/examples/qml/referenceexamples/coercion/person.cpp
deleted file mode 100644
index ab7aefcbee..0000000000
--- a/examples/qml/referenceexamples/coercion/person.cpp
+++ /dev/null
@@ -1,24 +0,0 @@
-// Copyright (C) 2021 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "person.h"
-
-QString Person::name() const
-{
- return m_name;
-}
-
-void Person::setName(const QString &n)
-{
- m_name = n;
-}
-
-int Person::shoeSize() const
-{
- return m_shoeSize;
-}
-
-void Person::setShoeSize(int s)
-{
- m_shoeSize = s;
-}
diff --git a/examples/qml/referenceexamples/default/birthdayparty.cpp b/examples/qml/referenceexamples/default/birthdayparty.cpp
deleted file mode 100644
index 5a9f38d9f3..0000000000
--- a/examples/qml/referenceexamples/default/birthdayparty.cpp
+++ /dev/null
@@ -1,30 +0,0 @@
-// Copyright (C) 2021 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "birthdayparty.h"
-
-Person *BirthdayParty::host() const
-{
- return m_host;
-}
-
-void BirthdayParty::setHost(Person *c)
-{
- m_host = c;
-}
-
-QQmlListProperty<Person> BirthdayParty::guests()
-{
- return {this, &m_guests};
-}
-
-qsizetype BirthdayParty::guestCount() const
-{
- return m_guests.count();
-}
-
-Person *BirthdayParty::guest(qsizetype index) const
-{
- return m_guests.at(index);
-}
-
diff --git a/examples/qml/referenceexamples/default/birthdayparty.h b/examples/qml/referenceexamples/default/birthdayparty.h
deleted file mode 100644
index ce5106ef99..0000000000
--- a/examples/qml/referenceexamples/default/birthdayparty.h
+++ /dev/null
@@ -1,35 +0,0 @@
-// Copyright (C) 2021 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef BIRTHDAYPARTY_H
-#define BIRTHDAYPARTY_H
-
-#include <QObject>
-#include <QQmlListProperty>
-#include "person.h"
-
-// ![0]
-class BirthdayParty : public QObject
-{
- Q_OBJECT
- Q_PROPERTY(Person *host READ host WRITE setHost)
- Q_PROPERTY(QQmlListProperty<Person> guests READ guests)
- Q_CLASSINFO("DefaultProperty", "guests")
- QML_ELEMENT
-public:
- using QObject::QObject;
-
- Person *host() const;
- void setHost(Person *);
-
- QQmlListProperty<Person> guests();
- qsizetype guestCount() const;
- Person *guest(qsizetype) const;
-
-private:
- Person *m_host = nullptr;
- QList<Person *> m_guests;
-};
-// ![0]
-
-#endif // BIRTHDAYPARTY_H
diff --git a/examples/qml/referenceexamples/default/default.qrc b/examples/qml/referenceexamples/default/default.qrc
deleted file mode 100644
index e2fa01d5e7..0000000000
--- a/examples/qml/referenceexamples/default/default.qrc
+++ /dev/null
@@ -1,5 +0,0 @@
-<!DOCTYPE RCC><RCC version="1.0">
-<qresource>
- <file>example.qml</file>
-</qresource>
-</RCC>
diff --git a/examples/qml/referenceexamples/default/person.cpp b/examples/qml/referenceexamples/default/person.cpp
deleted file mode 100644
index ab7aefcbee..0000000000
--- a/examples/qml/referenceexamples/default/person.cpp
+++ /dev/null
@@ -1,24 +0,0 @@
-// Copyright (C) 2021 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "person.h"
-
-QString Person::name() const
-{
- return m_name;
-}
-
-void Person::setName(const QString &n)
-{
- m_name = n;
-}
-
-int Person::shoeSize() const
-{
- return m_shoeSize;
-}
-
-void Person::setShoeSize(int s)
-{
- m_shoeSize = s;
-}
diff --git a/examples/qml/referenceexamples/extended/CMakeLists.txt b/examples/qml/referenceexamples/extended/CMakeLists.txt
deleted file mode 100644
index 6ecff60d0c..0000000000
--- a/examples/qml/referenceexamples/extended/CMakeLists.txt
+++ /dev/null
@@ -1,44 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(extended LANGUAGES CXX)
-
-set(CMAKE_AUTOMOC ON)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/qml/referenceexamples/extended")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Gui Qml Widgets)
-
-qt_add_executable(extended
- lineedit.cpp lineedit.h
- main.cpp
-)
-
-set_target_properties(extended PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(extended PUBLIC
- Qt::Core
- Qt::Gui
- Qt::Qml
- Qt::Widgets
-)
-
-qt_add_qml_module(extended
- URI People
- QML_FILES example.qml
- NO_RESOURCE_TARGET_PATH
-)
-
-install(TARGETS extended
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/qml/referenceexamples/extended/example.qml b/examples/qml/referenceexamples/extended/example.qml
deleted file mode 100644
index 8a0b3193d8..0000000000
--- a/examples/qml/referenceexamples/extended/example.qml
+++ /dev/null
@@ -1,10 +0,0 @@
-// Copyright (C) 2017 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-import People
-
-// ![0]
-QLineEdit {
- leftMargin: 20
-}
-// ![0]
diff --git a/examples/qml/referenceexamples/extended/extended.pro b/examples/qml/referenceexamples/extended/extended.pro
deleted file mode 100644
index 094e5201ca..0000000000
--- a/examples/qml/referenceexamples/extended/extended.pro
+++ /dev/null
@@ -1,13 +0,0 @@
-QT += qml widgets
-
-CONFIG += qmltypes
-QML_IMPORT_NAME = People
-QML_IMPORT_MAJOR_VERSION = 1
-
-SOURCES += main.cpp \
- lineedit.cpp
-HEADERS += lineedit.h
-RESOURCES += extended.qrc
-
-target.path = $$[QT_INSTALL_EXAMPLES]/qml/referenceexamples/extended
-INSTALLS += target
diff --git a/examples/qml/referenceexamples/extended/extended.qrc b/examples/qml/referenceexamples/extended/extended.qrc
deleted file mode 100644
index e2fa01d5e7..0000000000
--- a/examples/qml/referenceexamples/extended/extended.qrc
+++ /dev/null
@@ -1,5 +0,0 @@
-<!DOCTYPE RCC><RCC version="1.0">
-<qresource>
- <file>example.qml</file>
-</qresource>
-</RCC>
diff --git a/examples/qml/referenceexamples/extended/lineedit.cpp b/examples/qml/referenceexamples/extended/lineedit.cpp
deleted file mode 100644
index 802f47ef03..0000000000
--- a/examples/qml/referenceexamples/extended/lineedit.cpp
+++ /dev/null
@@ -1,71 +0,0 @@
-// Copyright (C) 2017 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-#include "lineedit.h"
-#include <qqml.h>
-
-LineEditExtension::LineEditExtension(QObject *object)
-: QObject(object), m_lineedit(qobject_cast<QLineEdit *>(object))
-{
-}
-
-int LineEditExtension::leftMargin() const
-{
- return m_lineedit->textMargins().left();
-}
-
-void LineEditExtension::setLeftMargin(int l)
-{
- QMargins m = m_lineedit->textMargins();
- if (m.left() != l) {
- m.setLeft(l);
- m_lineedit->setTextMargins(m);
- emit marginsChanged();
- }
-}
-
-int LineEditExtension::rightMargin() const
-{
- return m_lineedit->textMargins().right();
-}
-
-void LineEditExtension::setRightMargin(int r)
-{
- QMargins m = m_lineedit->textMargins();
- if (m.right() != r) {
- m.setRight(r);
- m_lineedit->setTextMargins(m);
- emit marginsChanged();
- }
-}
-
-int LineEditExtension::topMargin() const
-{
- return m_lineedit->textMargins().top();
-}
-
-void LineEditExtension::setTopMargin(int t)
-{
- QMargins m = m_lineedit->textMargins();
- if (m.top() != t) {
- m.setTop(t);
- m_lineedit->setTextMargins(m);
- emit marginsChanged();
- }
-}
-
-int LineEditExtension::bottomMargin() const
-{
- return m_lineedit->textMargins().bottom();
-}
-
-void LineEditExtension::setBottomMargin(int b)
-{
- QMargins m = m_lineedit->textMargins();
- if (m.bottom() != b) {
- m.setBottom(b);
- m_lineedit->setTextMargins(m);
- emit marginsChanged();
- }
-}
-
-
diff --git a/examples/qml/referenceexamples/extended/lineedit.h b/examples/qml/referenceexamples/extended/lineedit.h
deleted file mode 100644
index 44bb9fe72d..0000000000
--- a/examples/qml/referenceexamples/extended/lineedit.h
+++ /dev/null
@@ -1,47 +0,0 @@
-// Copyright (C) 2017 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-#ifndef LINEEDIT_H
-#define LINEEDIT_H
-
-#include <QLineEdit>
-#include <qqml.h>
-
-class LineEditExtension : public QObject
-{
- Q_OBJECT
- Q_PROPERTY(int leftMargin READ leftMargin WRITE setLeftMargin NOTIFY marginsChanged)
- Q_PROPERTY(int rightMargin READ rightMargin WRITE setRightMargin NOTIFY marginsChanged)
- Q_PROPERTY(int topMargin READ topMargin WRITE setTopMargin NOTIFY marginsChanged)
- Q_PROPERTY(int bottomMargin READ bottomMargin WRITE setBottomMargin NOTIFY marginsChanged)
-public:
- LineEditExtension(QObject *);
-
- int leftMargin() const;
- void setLeftMargin(int);
-
- int rightMargin() const;
- void setRightMargin(int);
-
- int topMargin() const;
- void setTopMargin(int);
-
- int bottomMargin() const;
- void setBottomMargin(int);
-signals:
- void marginsChanged();
-
-private:
- QLineEdit *m_lineedit;
-};
-
-// ![0]
-struct QLineEditForeign
-{
- Q_GADGET
- QML_FOREIGN(QLineEdit)
- QML_NAMED_ELEMENT(QLineEdit)
- QML_EXTENDED(LineEditExtension)
-};
-// ![0]
-
-#endif // LINEEDIT_H
diff --git a/examples/qml/referenceexamples/extended/main.cpp b/examples/qml/referenceexamples/extended/main.cpp
deleted file mode 100644
index 7861acf707..0000000000
--- a/examples/qml/referenceexamples/extended/main.cpp
+++ /dev/null
@@ -1,27 +0,0 @@
-// Copyright (C) 2017 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-#include <QApplication>
-#include <QQmlEngine>
-#include <QQmlComponent>
-#include <QDebug>
-#include <QLineEdit>
-#include "lineedit.h"
-
-int main(int argc, char ** argv)
-{
- QApplication app(argc, argv);
-
-// ![1]
- QQmlEngine engine;
- QQmlComponent component(&engine, QUrl("qrc:example.qml"));
- auto *edit = qobject_cast<QLineEdit *>(component.create());
-// ![1]
-
- if (edit) {
- edit->show();
- return QApplication::exec();
- }
-
- qWarning() << component.errors();
- return EXIT_FAILURE;
-}
diff --git a/examples/qml/referenceexamples/grouped/birthdayparty.cpp b/examples/qml/referenceexamples/grouped/birthdayparty.cpp
deleted file mode 100644
index 6cf8a608e7..0000000000
--- a/examples/qml/referenceexamples/grouped/birthdayparty.cpp
+++ /dev/null
@@ -1,29 +0,0 @@
-// Copyright (C) 2021 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "birthdayparty.h"
-
-Person *BirthdayParty::host() const
-{
- return m_host;
-}
-
-void BirthdayParty::setHost(Person *c)
-{
- m_host = c;
-}
-
-QQmlListProperty<Person> BirthdayParty::guests()
-{
- return {this, &m_guests};
-}
-
-qsizetype BirthdayParty::guestCount() const
-{
- return m_guests.count();
-}
-
-Person *BirthdayParty::guest(qsizetype index) const
-{
- return m_guests.at(index);
-}
diff --git a/examples/qml/referenceexamples/grouped/birthdayparty.h b/examples/qml/referenceexamples/grouped/birthdayparty.h
deleted file mode 100644
index 7f011ca95f..0000000000
--- a/examples/qml/referenceexamples/grouped/birthdayparty.h
+++ /dev/null
@@ -1,34 +0,0 @@
-// Copyright (C) 2021 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef BIRTHDAYPARTY_H
-#define BIRTHDAYPARTY_H
-
-#include <QObject>
-#include <QQmlListProperty>
-#include "person.h"
-
-class BirthdayParty : public QObject
-{
- Q_OBJECT
- Q_PROPERTY(Person *host READ host WRITE setHost)
- Q_PROPERTY(QQmlListProperty<Person> guests READ guests)
- Q_CLASSINFO("DefaultProperty", "guests")
- QML_ELEMENT
-public:
- using QObject::QObject;
-
- Person *host() const;
- void setHost(Person *);
-
- QQmlListProperty<Person> guests();
- qsizetype guestCount() const;
- Person *guest(qsizetype) const;
-
-private:
- Person *m_host;
- QList<Person *> m_guests;
-};
-
-
-#endif // BIRTHDAYPARTY_H
diff --git a/examples/qml/referenceexamples/grouped/grouped.qrc b/examples/qml/referenceexamples/grouped/grouped.qrc
deleted file mode 100644
index e2fa01d5e7..0000000000
--- a/examples/qml/referenceexamples/grouped/grouped.qrc
+++ /dev/null
@@ -1,5 +0,0 @@
-<!DOCTYPE RCC><RCC version="1.0">
-<qresource>
- <file>example.qml</file>
-</qresource>
-</RCC>
diff --git a/examples/qml/referenceexamples/grouped/person.cpp b/examples/qml/referenceexamples/grouped/person.cpp
deleted file mode 100644
index 358fbf0ed8..0000000000
--- a/examples/qml/referenceexamples/grouped/person.cpp
+++ /dev/null
@@ -1,59 +0,0 @@
-// Copyright (C) 2021 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "person.h"
-
-int ShoeDescription::size() const
-{
- return m_size;
-}
-
-void ShoeDescription::setSize(int s)
-{
- m_size = s;
-}
-
-QColor ShoeDescription::color() const
-{
- return m_color;
-}
-
-void ShoeDescription::setColor(const QColor &c)
-{
- m_color = c;
-}
-
-QString ShoeDescription::brand() const
-{
- return m_brand;
-}
-
-void ShoeDescription::setBrand(const QString &b)
-{
- m_brand = b;
-}
-
-qreal ShoeDescription::price() const
-{
- return m_price;
-}
-
-void ShoeDescription::setPrice(qreal p)
-{
- m_price = p;
-}
-
-QString Person::name() const
-{
- return m_name;
-}
-
-void Person::setName(const QString &n)
-{
- m_name = n;
-}
-
-ShoeDescription *Person::shoe()
-{
- return &m_shoe;
-}
diff --git a/examples/qml/referenceexamples/methods/birthdayparty.cpp b/examples/qml/referenceexamples/methods/birthdayparty.cpp
deleted file mode 100644
index 35ae42f779..0000000000
--- a/examples/qml/referenceexamples/methods/birthdayparty.cpp
+++ /dev/null
@@ -1,39 +0,0 @@
-// Copyright (C) 2021 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "birthdayparty.h"
-
-// ![0]
-Person *BirthdayParty::host() const
-{
- return m_host;
-}
-
-void BirthdayParty::setHost(Person *c)
-{
- m_host = c;
-}
-
-QQmlListProperty<Person> BirthdayParty::guests()
-{
- return {this, &m_guests};
-}
-
-qsizetype BirthdayParty::guestCount() const
-{
- return m_guests.count();
-}
-
-Person *BirthdayParty::guest(qsizetype index) const
-{
- return m_guests.at(index);
-}
-
-void BirthdayParty::invite(const QString &name)
-{
- auto *person = new Person(this);
- person->setName(name);
- m_guests.append(person);
-}
-// ![0]
-
diff --git a/examples/qml/referenceexamples/methods/birthdayparty.h b/examples/qml/referenceexamples/methods/birthdayparty.h
deleted file mode 100644
index 796464c333..0000000000
--- a/examples/qml/referenceexamples/methods/birthdayparty.h
+++ /dev/null
@@ -1,36 +0,0 @@
-// Copyright (C) 2021 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef BIRTHDAYPARTY_H
-#define BIRTHDAYPARTY_H
-
-#include <QObject>
-#include <QQmlListProperty>
-#include "person.h"
-
-class BirthdayParty : public QObject
-{
- Q_OBJECT
- Q_PROPERTY(Person *host READ host WRITE setHost)
- Q_PROPERTY(QQmlListProperty<Person> guests READ guests)
- QML_ELEMENT
-public:
- using QObject::QObject;
-
- Person *host() const;
- void setHost(Person *);
-
- QQmlListProperty<Person> guests();
- qsizetype guestCount() const;
- Person *guest(qsizetype) const;
-
-// ![0]
- Q_INVOKABLE void invite(const QString &name);
-// ![0]
-
-private:
- Person *m_host = nullptr;
- QList<Person *> m_guests;
-};
-
-#endif // BIRTHDAYPARTY_H
diff --git a/examples/qml/referenceexamples/methods/example.qml b/examples/qml/referenceexamples/methods/example.qml
deleted file mode 100644
index 41d053edd2..0000000000
--- a/examples/qml/referenceexamples/methods/example.qml
+++ /dev/null
@@ -1,21 +0,0 @@
-// Copyright (C) 2017 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-// ![0]
-import QtQuick
-import People
-
-BirthdayParty {
- host: Person {
- name: "Bob Jones"
- shoeSize: 12
- }
- guests: [
- Person { name: "Leo Hodges" },
- Person { name: "Jack Smith" },
- Person { name: "Anne Brown" }
- ]
-
- Component.onCompleted: invite("William Green")
-}
-// ![0]
diff --git a/examples/qml/referenceexamples/methods/methods.qrc b/examples/qml/referenceexamples/methods/methods.qrc
deleted file mode 100644
index e2fa01d5e7..0000000000
--- a/examples/qml/referenceexamples/methods/methods.qrc
+++ /dev/null
@@ -1,5 +0,0 @@
-<!DOCTYPE RCC><RCC version="1.0">
-<qresource>
- <file>example.qml</file>
-</qresource>
-</RCC>
diff --git a/examples/qml/referenceexamples/methods/person.cpp b/examples/qml/referenceexamples/methods/person.cpp
deleted file mode 100644
index ab7aefcbee..0000000000
--- a/examples/qml/referenceexamples/methods/person.cpp
+++ /dev/null
@@ -1,24 +0,0 @@
-// Copyright (C) 2021 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "person.h"
-
-QString Person::name() const
-{
- return m_name;
-}
-
-void Person::setName(const QString &n)
-{
- m_name = n;
-}
-
-int Person::shoeSize() const
-{
- return m_shoeSize;
-}
-
-void Person::setShoeSize(int s)
-{
- m_shoeSize = s;
-}
diff --git a/examples/qml/referenceexamples/methods/person.h b/examples/qml/referenceexamples/methods/person.h
deleted file mode 100644
index d8d4941183..0000000000
--- a/examples/qml/referenceexamples/methods/person.h
+++ /dev/null
@@ -1,30 +0,0 @@
-// Copyright (C) 2021 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef PERSON_H
-#define PERSON_H
-
-#include <QObject>
-#include <QtQml/qqml.h>
-
-class Person : public QObject
-{
- Q_OBJECT
- Q_PROPERTY(QString name READ name WRITE setName)
- Q_PROPERTY(int shoeSize READ shoeSize WRITE setShoeSize)
- QML_ELEMENT
-public:
- using QObject::QObject;
-
- QString name() const;
- void setName(const QString &);
-
- int shoeSize() const;
- void setShoeSize(int);
-
-private:
- QString m_name;
- int m_shoeSize = 0;
-};
-
-#endif // PERSON_H
diff --git a/examples/qml/referenceexamples/properties/CMakeLists.txt b/examples/qml/referenceexamples/properties/CMakeLists.txt
deleted file mode 100644
index dbe521d17d..0000000000
--- a/examples/qml/referenceexamples/properties/CMakeLists.txt
+++ /dev/null
@@ -1,43 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(properties LANGUAGES CXX)
-
-set(CMAKE_AUTOMOC ON)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/qml/referenceexamples/properties")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Qml)
-
-qt_add_executable(properties
- birthdayparty.cpp birthdayparty.h
- main.cpp
- person.cpp person.h
-)
-
-set_target_properties(properties PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(properties PUBLIC
- Qt::Core
- Qt::Qml
-)
-
-qt_add_qml_module(properties
- URI People
- QML_FILES example.qml
- NO_RESOURCE_TARGET_PATH
-)
-
-install(TARGETS properties
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/qml/referenceexamples/properties/birthdayparty.cpp b/examples/qml/referenceexamples/properties/birthdayparty.cpp
deleted file mode 100644
index 2f97634abc..0000000000
--- a/examples/qml/referenceexamples/properties/birthdayparty.cpp
+++ /dev/null
@@ -1,87 +0,0 @@
-// Copyright (C) 2021 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "birthdayparty.h"
-
-// ![0]
-Person *BirthdayParty::host() const
-{
- return m_host;
-}
-
-void BirthdayParty::setHost(Person *c)
-{
- m_host = c;
-}
-
-QQmlListProperty<Person> BirthdayParty::guests()
-{
- return {this, this,
- &BirthdayParty::appendGuest,
- &BirthdayParty::guestCount,
- &BirthdayParty::guest,
- &BirthdayParty::clearGuests,
- &BirthdayParty::replaceGuest,
- &BirthdayParty::removeLastGuest};
-}
-
-void BirthdayParty::appendGuest(Person *p)
-{
- m_guests.append(p);
-}
-
-qsizetype BirthdayParty::guestCount() const
-{
- return m_guests.count();
-}
-
-Person *BirthdayParty::guest(qsizetype index) const
-{
- return m_guests.at(index);
-}
-
-void BirthdayParty::clearGuests() {
- m_guests.clear();
-}
-
-void BirthdayParty::replaceGuest(qsizetype index, Person *p)
-{
- m_guests[index] = p;
-}
-
-void BirthdayParty::removeLastGuest()
-{
- m_guests.removeLast();
-}
-
-// ![0]
-
-void BirthdayParty::appendGuest(QQmlListProperty<Person> *list, Person *p)
-{
- reinterpret_cast< BirthdayParty *>(list->data)->appendGuest(p);
-}
-
-void BirthdayParty::clearGuests(QQmlListProperty<Person>* list)
-{
- reinterpret_cast< BirthdayParty *>(list->data)->clearGuests();
-}
-
-void BirthdayParty::replaceGuest(QQmlListProperty<Person> *list, qsizetype i, Person *p)
-{
- reinterpret_cast< BirthdayParty* >(list->data)->replaceGuest(i, p);
-}
-
-void BirthdayParty::removeLastGuest(QQmlListProperty<Person> *list)
-{
- reinterpret_cast< BirthdayParty* >(list->data)->removeLastGuest();
-}
-
-Person* BirthdayParty::guest(QQmlListProperty<Person> *list, qsizetype i)
-{
- return reinterpret_cast< BirthdayParty* >(list->data)->guest(i);
-}
-
-qsizetype BirthdayParty::guestCount(QQmlListProperty<Person> *list)
-{
- return reinterpret_cast< BirthdayParty* >(list->data)->guestCount();
-}
diff --git a/examples/qml/referenceexamples/properties/main.cpp b/examples/qml/referenceexamples/properties/main.cpp
deleted file mode 100644
index f381686dbc..0000000000
--- a/examples/qml/referenceexamples/properties/main.cpp
+++ /dev/null
@@ -1,28 +0,0 @@
-// Copyright (C) 2017 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-#include <QCoreApplication>
-#include <QQmlEngine>
-#include <QQmlComponent>
-#include <QDebug>
-#include "birthdayparty.h"
-#include "person.h"
-
-int main(int argc, char ** argv)
-{
- QCoreApplication app(argc, argv);
-
- QQmlEngine engine;
- QQmlComponent component(&engine, QUrl("qrc:example.qml"));
- auto *party = qobject_cast<BirthdayParty *>(component.create());
-
- if (party && party->host()) {
- qInfo() << party->host()->name() << "is having a birthday!\n"
- "They are inviting:";
- for (qsizetype ii = 0; ii < party->guestCount(); ++ii)
- qInfo() << " " << party->guest(ii)->name();
- return EXIT_SUCCESS;
- }
-
- qWarning() << component.errors();
- return EXIT_FAILURE;
-}
diff --git a/examples/qml/referenceexamples/properties/person.cpp b/examples/qml/referenceexamples/properties/person.cpp
deleted file mode 100644
index ab7aefcbee..0000000000
--- a/examples/qml/referenceexamples/properties/person.cpp
+++ /dev/null
@@ -1,24 +0,0 @@
-// Copyright (C) 2021 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "person.h"
-
-QString Person::name() const
-{
- return m_name;
-}
-
-void Person::setName(const QString &n)
-{
- m_name = n;
-}
-
-int Person::shoeSize() const
-{
- return m_shoeSize;
-}
-
-void Person::setShoeSize(int s)
-{
- m_shoeSize = s;
-}
diff --git a/examples/qml/referenceexamples/properties/person.h b/examples/qml/referenceexamples/properties/person.h
deleted file mode 100644
index d8d4941183..0000000000
--- a/examples/qml/referenceexamples/properties/person.h
+++ /dev/null
@@ -1,30 +0,0 @@
-// Copyright (C) 2021 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef PERSON_H
-#define PERSON_H
-
-#include <QObject>
-#include <QtQml/qqml.h>
-
-class Person : public QObject
-{
- Q_OBJECT
- Q_PROPERTY(QString name READ name WRITE setName)
- Q_PROPERTY(int shoeSize READ shoeSize WRITE setShoeSize)
- QML_ELEMENT
-public:
- using QObject::QObject;
-
- QString name() const;
- void setName(const QString &);
-
- int shoeSize() const;
- void setShoeSize(int);
-
-private:
- QString m_name;
- int m_shoeSize = 0;
-};
-
-#endif // PERSON_H
diff --git a/examples/qml/referenceexamples/properties/properties.pro b/examples/qml/referenceexamples/properties/properties.pro
deleted file mode 100644
index 6697afa2c5..0000000000
--- a/examples/qml/referenceexamples/properties/properties.pro
+++ /dev/null
@@ -1,15 +0,0 @@
-QT = core qml
-
-CONFIG += qmltypes
-QML_IMPORT_NAME = People
-QML_IMPORT_MAJOR_VERSION = 1
-
-SOURCES += main.cpp \
- person.cpp \
- birthdayparty.cpp
-HEADERS += person.h \
- birthdayparty.h
-RESOURCES += properties.qrc
-
-target.path = $$[QT_INSTALL_EXAMPLES]/qml/referenceexamples/properties
-INSTALLS += target
diff --git a/examples/qml/referenceexamples/properties/properties.qrc b/examples/qml/referenceexamples/properties/properties.qrc
deleted file mode 100644
index e2fa01d5e7..0000000000
--- a/examples/qml/referenceexamples/properties/properties.qrc
+++ /dev/null
@@ -1,5 +0,0 @@
-<!DOCTYPE RCC><RCC version="1.0">
-<qresource>
- <file>example.qml</file>
-</qresource>
-</RCC>
diff --git a/examples/qml/referenceexamples/referenceexamples.pro b/examples/qml/referenceexamples/referenceexamples.pro
deleted file mode 100644
index 3f4bbcf75d..0000000000
--- a/examples/qml/referenceexamples/referenceexamples.pro
+++ /dev/null
@@ -1,17 +0,0 @@
-TEMPLATE = subdirs
-
-SUBDIRS += \
- adding \
- coercion \
- default \
- properties \
- methods
-
-qtHaveModule(widgets): SUBDIRS += extended
-
-qtHaveModule(quick): SUBDIRS += \
- attached \
- binding \
- grouped \
- signal \
- valuesource
diff --git a/examples/qml/referenceexamples/referenceexamples.qmlproject b/examples/qml/referenceexamples/referenceexamples.qmlproject
deleted file mode 100644
index 2bb4016996..0000000000
--- a/examples/qml/referenceexamples/referenceexamples.qmlproject
+++ /dev/null
@@ -1,14 +0,0 @@
-import QmlProject 1.0
-
-Project {
- /* Include .qml, .js, and image files from current directory and subdirectories */
- QmlFiles {
- directory: "."
- }
- JavaScriptFiles {
- directory: "."
- }
- ImageFiles {
- directory: "."
- }
-}
diff --git a/examples/qml/referenceexamples/signal/CMakeLists.txt b/examples/qml/referenceexamples/signal/CMakeLists.txt
deleted file mode 100644
index ce196f3a38..0000000000
--- a/examples/qml/referenceexamples/signal/CMakeLists.txt
+++ /dev/null
@@ -1,44 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(signal LANGUAGES CXX)
-
-set(CMAKE_AUTOMOC ON)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/qml/referenceexamples/signal")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Gui Qml)
-
-qt_add_executable(signal
- birthdayparty.cpp birthdayparty.h
- main.cpp
- person.cpp person.h
-)
-
-set_target_properties(signal PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(signal PUBLIC
- Qt::Core
- Qt::Gui
- Qt::Qml
-)
-
-qt_add_qml_module(signal
- URI People
- QML_FILES example.qml
- NO_RESOURCE_TARGET_PATH
-)
-
-install(TARGETS signal
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/qml/referenceexamples/signal/birthdayparty.cpp b/examples/qml/referenceexamples/signal/birthdayparty.cpp
deleted file mode 100644
index b2cc131597..0000000000
--- a/examples/qml/referenceexamples/signal/birthdayparty.cpp
+++ /dev/null
@@ -1,51 +0,0 @@
-// Copyright (C) 2021 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "birthdayparty.h"
-
-QDate BirthdayPartyAttached::rsvp() const
-{
- return m_rsvp;
-}
-
-void BirthdayPartyAttached::setRsvp(QDate d)
-{
- m_rsvp = d;
-}
-
-Person *BirthdayParty::host() const
-{
- return m_host;
-}
-
-void BirthdayParty::setHost(Person *c)
-{
- m_host = c;
-}
-
-QQmlListProperty<Person> BirthdayParty::guests()
-{
- return {this, &m_guests};
-}
-
-qsizetype BirthdayParty::guestCount() const
-{
- return m_guests.count();
-}
-
-Person *BirthdayParty::guest(qsizetype index) const
-{
- return m_guests.at(index);
-}
-
-void BirthdayParty::startParty()
-{
- QTime time = QTime::currentTime();
- emit partyStarted(time);
-}
-
-BirthdayPartyAttached *BirthdayParty::qmlAttachedProperties(QObject *object)
-{
- return new BirthdayPartyAttached(object);
-}
-
diff --git a/examples/qml/referenceexamples/signal/birthdayparty.h b/examples/qml/referenceexamples/signal/birthdayparty.h
deleted file mode 100644
index 22f3bdf9da..0000000000
--- a/examples/qml/referenceexamples/signal/birthdayparty.h
+++ /dev/null
@@ -1,57 +0,0 @@
-// Copyright (C) 2017 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-#ifndef BIRTHDAYPARTY_H
-#define BIRTHDAYPARTY_H
-
-#include <QObject>
-#include <QDate>
-#include <qqml.h>
-#include "person.h"
-
-class BirthdayPartyAttached : public QObject
-{
- Q_OBJECT
- Q_PROPERTY(QDate rsvp READ rsvp WRITE setRsvp)
- QML_ANONYMOUS
-public:
- using QObject::QObject;
-
- QDate rsvp() const;
- void setRsvp(QDate);
-
-private:
- QDate m_rsvp;
-};
-
-class BirthdayParty : public QObject
-{
- Q_OBJECT
- Q_PROPERTY(Person *host READ host WRITE setHost)
- Q_PROPERTY(QQmlListProperty<Person> guests READ guests)
- Q_CLASSINFO("DefaultProperty", "guests")
- QML_ELEMENT
- QML_ATTACHED(BirthdayPartyAttached)
-public:
- using QObject::QObject;
-
- Person *host() const;
- void setHost(Person *);
-
- QQmlListProperty<Person> guests();
- qsizetype guestCount() const;
- Person *guest(qsizetype) const;
-
- static BirthdayPartyAttached *qmlAttachedProperties(QObject *);
-
- void startParty();
-// ![0]
-signals:
- void partyStarted(QTime time);
-// ![0]
-
-private:
- Person *m_host = nullptr;
- QList<Person *> m_guests;
-};
-
-#endif // BIRTHDAYPARTY_H
diff --git a/examples/qml/referenceexamples/signal/example.qml b/examples/qml/referenceexamples/signal/example.qml
deleted file mode 100644
index c35db2fe46..0000000000
--- a/examples/qml/referenceexamples/signal/example.qml
+++ /dev/null
@@ -1,36 +0,0 @@
-// Copyright (C) 2017 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-import People
-import QtQuick // For QColor
-
-BirthdayParty {
-// ![0]
- onPartyStarted: (time) => { console.log("This party started rockin' at " + time); }
-// ![0]
-
- host: Boy {
- name: "Bob Jones"
- shoe { size: 12; color: "white"; brand: "Nike"; price: 90.0 }
- }
-
- Boy {
- name: "Leo Hodges"
- BirthdayParty.rsvp: "2009-07-06"
- shoe { size: 10; color: "black"; brand: "Reebok"; price: 59.95 }
- }
- Boy {
- name: "Jack Smith"
- shoe { size: 8; color: "blue"; brand: "Puma"; price: 19.95 }
- }
- Girl {
- name: "Anne Brown"
- BirthdayParty.rsvp: "2009-07-01"
- shoe.size: 7
- shoe.color: "red"
- shoe.brand: "Marc Jacobs"
- shoe.price: 699.99
- }
-// ![1]
-}
-// ![1]
diff --git a/examples/qml/referenceexamples/signal/main.cpp b/examples/qml/referenceexamples/signal/main.cpp
deleted file mode 100644
index f99ddeb6c7..0000000000
--- a/examples/qml/referenceexamples/signal/main.cpp
+++ /dev/null
@@ -1,47 +0,0 @@
-// Copyright (C) 2017 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-#include <QCoreApplication>
-#include <QQmlEngine>
-#include <QQmlComponent>
-#include <QDebug>
-#include "birthdayparty.h"
-#include "person.h"
-
-int main(int argc, char ** argv)
-{
- QCoreApplication app(argc, argv);
-
- QQmlEngine engine;
- QQmlComponent component(&engine, QUrl("qrc:example.qml"));
- auto *party = qobject_cast<BirthdayParty *>(component.create());
-
- if (party && party->host()) {
- qInfo() << party->host()->name() << "is having a birthday!";
-
- if (qobject_cast<Boy *>(party->host()))
- qInfo() << "He is inviting:";
- else
- qInfo() << "She is inviting:";
-
- for (qsizetype ii = 0; ii < party->guestCount(); ++ii) {
- Person *guest = party->guest(ii);
-
- QDate rsvpDate;
- QObject *attached =
- qmlAttachedPropertiesObject<BirthdayParty>(guest, false);
- if (attached)
- rsvpDate = attached->property("rsvp").toDate();
-
- if (rsvpDate.isNull())
- qInfo() << " " << guest->name() << "RSVP date: Hasn't RSVP'd";
- else
- qInfo() << " " << guest->name() << "RSVP date:" << rsvpDate.toString();
- }
-
- party->startParty();
- return EXIT_SUCCESS;
- }
-
- qWarning() << component.errors();
- return EXIT_FAILURE;
-}
diff --git a/examples/qml/referenceexamples/signal/person.cpp b/examples/qml/referenceexamples/signal/person.cpp
deleted file mode 100644
index 358fbf0ed8..0000000000
--- a/examples/qml/referenceexamples/signal/person.cpp
+++ /dev/null
@@ -1,59 +0,0 @@
-// Copyright (C) 2021 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "person.h"
-
-int ShoeDescription::size() const
-{
- return m_size;
-}
-
-void ShoeDescription::setSize(int s)
-{
- m_size = s;
-}
-
-QColor ShoeDescription::color() const
-{
- return m_color;
-}
-
-void ShoeDescription::setColor(const QColor &c)
-{
- m_color = c;
-}
-
-QString ShoeDescription::brand() const
-{
- return m_brand;
-}
-
-void ShoeDescription::setBrand(const QString &b)
-{
- m_brand = b;
-}
-
-qreal ShoeDescription::price() const
-{
- return m_price;
-}
-
-void ShoeDescription::setPrice(qreal p)
-{
- m_price = p;
-}
-
-QString Person::name() const
-{
- return m_name;
-}
-
-void Person::setName(const QString &n)
-{
- m_name = n;
-}
-
-ShoeDescription *Person::shoe()
-{
- return &m_shoe;
-}
diff --git a/examples/qml/referenceexamples/signal/signal.pro b/examples/qml/referenceexamples/signal/signal.pro
deleted file mode 100644
index 3c31234b3c..0000000000
--- a/examples/qml/referenceexamples/signal/signal.pro
+++ /dev/null
@@ -1,15 +0,0 @@
-QT += qml
-
-CONFIG += qmltypes
-QML_IMPORT_NAME = People
-QML_IMPORT_MAJOR_VERSION = 1
-
-SOURCES += main.cpp \
- person.cpp \
- birthdayparty.cpp
-HEADERS += person.h \
- birthdayparty.h
-RESOURCES += signal.qrc
-
-target.path = $$[QT_INSTALL_EXAMPLES]/qml/referenceexamples/signal
-INSTALLS += target
diff --git a/examples/qml/referenceexamples/signal/signal.qrc b/examples/qml/referenceexamples/signal/signal.qrc
deleted file mode 100644
index e2fa01d5e7..0000000000
--- a/examples/qml/referenceexamples/signal/signal.qrc
+++ /dev/null
@@ -1,5 +0,0 @@
-<!DOCTYPE RCC><RCC version="1.0">
-<qresource>
- <file>example.qml</file>
-</qresource>
-</RCC>
diff --git a/examples/qml/referenceexamples/valuesource/birthdayparty.cpp b/examples/qml/referenceexamples/valuesource/birthdayparty.cpp
deleted file mode 100644
index ba8b8829e7..0000000000
--- a/examples/qml/referenceexamples/valuesource/birthdayparty.cpp
+++ /dev/null
@@ -1,60 +0,0 @@
-// Copyright (C) 2021 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "birthdayparty.h"
-
-QDate BirthdayPartyAttached::rsvp() const
-{
- return m_rsvp;
-}
-
-void BirthdayPartyAttached::setRsvp(QDate d)
-{
- m_rsvp = d;
-}
-
-Person *BirthdayParty::host() const
-{
- return m_host;
-}
-
-void BirthdayParty::setHost(Person *c)
-{
- m_host = c;
-}
-
-QQmlListProperty<Person> BirthdayParty::guests()
-{
- return {this, &m_guests};
-}
-
-qsizetype BirthdayParty::guestCount() const
-{
- return m_guests.count();
-}
-
-Person *BirthdayParty::guest(qsizetype index) const
-{
- return m_guests.at(index);
-}
-
-void BirthdayParty::startParty()
-{
- QTime time = QTime::currentTime();
- emit partyStarted(time);
-}
-
-QString BirthdayParty::announcement() const
-{
- return QString();
-}
-
-void BirthdayParty::setAnnouncement(const QString &speak)
-{
- qInfo().noquote() << speak;
-}
-
-BirthdayPartyAttached *BirthdayParty::qmlAttachedProperties(QObject *object)
-{
- return new BirthdayPartyAttached(object);
-}
diff --git a/examples/qml/referenceexamples/valuesource/person.cpp b/examples/qml/referenceexamples/valuesource/person.cpp
deleted file mode 100644
index 358fbf0ed8..0000000000
--- a/examples/qml/referenceexamples/valuesource/person.cpp
+++ /dev/null
@@ -1,59 +0,0 @@
-// Copyright (C) 2021 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "person.h"
-
-int ShoeDescription::size() const
-{
- return m_size;
-}
-
-void ShoeDescription::setSize(int s)
-{
- m_size = s;
-}
-
-QColor ShoeDescription::color() const
-{
- return m_color;
-}
-
-void ShoeDescription::setColor(const QColor &c)
-{
- m_color = c;
-}
-
-QString ShoeDescription::brand() const
-{
- return m_brand;
-}
-
-void ShoeDescription::setBrand(const QString &b)
-{
- m_brand = b;
-}
-
-qreal ShoeDescription::price() const
-{
- return m_price;
-}
-
-void ShoeDescription::setPrice(qreal p)
-{
- m_price = p;
-}
-
-QString Person::name() const
-{
- return m_name;
-}
-
-void Person::setName(const QString &n)
-{
- m_name = n;
-}
-
-ShoeDescription *Person::shoe()
-{
- return &m_shoe;
-}
diff --git a/examples/qml/referenceexamples/valuesource/person.h b/examples/qml/referenceexamples/valuesource/person.h
deleted file mode 100644
index b5fa469025..0000000000
--- a/examples/qml/referenceexamples/valuesource/person.h
+++ /dev/null
@@ -1,77 +0,0 @@
-// Copyright (C) 2021 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef PERSON_H
-#define PERSON_H
-
-#include <QObject>
-#include <QColor>
-#include <QtQml/qqml.h>
-
-class ShoeDescription : public QObject
-{
- Q_OBJECT
- Q_PROPERTY(int size READ size WRITE setSize)
- Q_PROPERTY(QColor color READ color WRITE setColor)
- Q_PROPERTY(QString brand READ brand WRITE setBrand)
- Q_PROPERTY(qreal price READ price WRITE setPrice)
- QML_ANONYMOUS
-public:
- using QObject::QObject;
-
- int size() const;
- void setSize(int);
-
- QColor color() const;
- void setColor(const QColor &);
-
- QString brand() const;
- void setBrand(const QString &);
-
- qreal price() const;
- void setPrice(qreal);
-
-private:
- int m_size = 0;
- QColor m_color;
- QString m_brand;
- qreal m_price = 0;
-};
-
-class Person : public QObject
-{
- Q_OBJECT
- Q_PROPERTY(QString name READ name WRITE setName)
-// ![1]
- Q_PROPERTY(ShoeDescription *shoe READ shoe)
-// ![1]
- QML_ANONYMOUS
-public:
- using QObject::QObject;
-
- QString name() const;
- void setName(const QString &);
-
- ShoeDescription *shoe();
-private:
- QString m_name;
- ShoeDescription m_shoe;
-};
-
-class Boy : public Person
-{
- Q_OBJECT
- QML_ELEMENT
-public:
- using Person::Person;
-};
-
-class Girl : public Person
-{
- Q_OBJECT
- QML_ELEMENT
-public:
- using Person::Person;
-};
-
-#endif // PERSON_H
diff --git a/examples/qml/referenceexamples/valuesource/valuesource.qrc b/examples/qml/referenceexamples/valuesource/valuesource.qrc
deleted file mode 100644
index e2fa01d5e7..0000000000
--- a/examples/qml/referenceexamples/valuesource/valuesource.qrc
+++ /dev/null
@@ -1,5 +0,0 @@
-<!DOCTYPE RCC><RCC version="1.0">
-<qresource>
- <file>example.qml</file>
-</qresource>
-</RCC>
diff --git a/examples/qml/tutorials/extending-qml-advanced/CMakeLists.txt b/examples/qml/tutorials/extending-qml-advanced/CMakeLists.txt
new file mode 100644
index 0000000000..5541a8761d
--- /dev/null
+++ b/examples/qml/tutorials/extending-qml-advanced/CMakeLists.txt
@@ -0,0 +1,10 @@
+# Copyright (C) 2023 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+qt_internal_add_example(advanced1-Base-project)
+qt_internal_add_example(advanced2-Inheritance-and-coercion)
+qt_internal_add_example(advanced3-Default-properties)
+qt_internal_add_example(advanced4-Grouped-properties)
+qt_internal_add_example(advanced5-Attached-properties)
+qt_internal_add_example(advanced6-Property-value-source)
+qt_internal_add_example(advanced7-Extension-objects)
diff --git a/examples/qml/referenceexamples/methods/CMakeLists.txt b/examples/qml/tutorials/extending-qml-advanced/advanced1-Base-project/CMakeLists.txt
index 57c0733723..a8064b77ef 100644
--- a/examples/qml/referenceexamples/methods/CMakeLists.txt
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced1-Base-project/CMakeLists.txt
@@ -2,41 +2,41 @@
# SPDX-License-Identifier: BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
-project(methods LANGUAGES CXX)
-
-set(CMAKE_AUTOMOC ON)
+project(baseproject LANGUAGES CXX)
if(NOT DEFINED INSTALL_EXAMPLESDIR)
set(INSTALL_EXAMPLESDIR "examples")
endif()
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/qml/referenceexamples/methods")
+set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/qml/tutorials/extending-qml-advanced/advanced1-Basic-project")
find_package(Qt6 REQUIRED COMPONENTS Core Qml)
+qt_standard_project_setup()
+
+qt_policy(SET QTP0001 NEW)
-qt_add_executable(methods
+qt_add_executable(baseproject
birthdayparty.cpp birthdayparty.h
main.cpp
person.cpp person.h
)
-set_target_properties(methods PROPERTIES
+set_target_properties(baseproject PROPERTIES
WIN32_EXECUTABLE TRUE
MACOSX_BUNDLE TRUE
)
-target_link_libraries(methods PUBLIC
+target_link_libraries(baseproject PUBLIC
Qt::Core
Qt::Qml
)
-qt_add_qml_module(methods
+qt_add_qml_module(baseproject
URI People
- QML_FILES example.qml
- NO_RESOURCE_TARGET_PATH
+ QML_FILES Main.qml
)
-install(TARGETS methods
+install(TARGETS baseproject
RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
diff --git a/examples/qml/referenceexamples/properties/example.qml b/examples/qml/tutorials/extending-qml-advanced/advanced1-Base-project/Main.qml
index 52fb3344f0..c917d5b1f1 100644
--- a/examples/qml/referenceexamples/properties/example.qml
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced1-Base-project/Main.qml
@@ -1,9 +1,8 @@
-// Copyright (C) 2017 The Qt Company Ltd.
+// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
import People
-// ![0]
BirthdayParty {
host: Person {
name: "Bob Jones"
@@ -15,4 +14,3 @@ BirthdayParty {
Person { name: "Anne Brown" }
]
}
-// ![0]
diff --git a/examples/qml/referenceexamples/methods/methods.pro b/examples/qml/tutorials/extending-qml-advanced/advanced1-Base-project/baseproject.pro
index 2a5f3cff41..26c865fbba 100644
--- a/examples/qml/referenceexamples/methods/methods.pro
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced1-Base-project/baseproject.pro
@@ -9,7 +9,5 @@ SOURCES += main.cpp \
birthdayparty.cpp
HEADERS += person.h \
birthdayparty.h
-RESOURCES += methods.qrc
-target.path = $$[QT_INSTALL_EXAMPLES]/qml/referenceexamples/methods
-INSTALLS += target
+RESOURCES += baseproject.qrc
diff --git a/examples/qml/tutorials/extending-qml-advanced/advanced1-Base-project/baseproject.qrc b/examples/qml/tutorials/extending-qml-advanced/advanced1-Base-project/baseproject.qrc
new file mode 100644
index 0000000000..b1eeb489e2
--- /dev/null
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced1-Base-project/baseproject.qrc
@@ -0,0 +1,6 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource prefix="/qt/qml/People/">
+ <file>Main.qml</file>
+ <file alias="qmldir">qmldir.in</file>
+</qresource>
+</RCC>
diff --git a/examples/qml/tutorials/extending-qml-advanced/advanced1-Base-project/birthdayparty.cpp b/examples/qml/tutorials/extending-qml-advanced/advanced1-Base-project/birthdayparty.cpp
new file mode 100644
index 0000000000..ad38f284e7
--- /dev/null
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced1-Base-project/birthdayparty.cpp
@@ -0,0 +1,99 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+#include "birthdayparty.h"
+
+Person *BirthdayParty::host() const
+{
+ return m_host;
+}
+
+void BirthdayParty::setHost(Person *host)
+{
+ if (m_host != host) {
+ m_host = host;
+ emit hostChanged();
+ }
+}
+
+QQmlListProperty<Person> BirthdayParty::guests()
+{
+ return { this,
+ this,
+ &BirthdayParty::appendGuest,
+ &BirthdayParty::guestCount,
+ &BirthdayParty::guest,
+ &BirthdayParty::clearGuests,
+ &BirthdayParty::replaceGuest,
+ &BirthdayParty::removeLastGuest };
+}
+
+void BirthdayParty::appendGuest(Person *guest)
+{
+ m_guests.append(guest);
+ emit guestsChanged();
+}
+
+qsizetype BirthdayParty::guestCount() const
+{
+ return m_guests.count();
+}
+
+Person *BirthdayParty::guest(qsizetype index) const
+{
+ return m_guests.at(index);
+}
+
+void BirthdayParty::clearGuests()
+{
+ if (!m_guests.empty()) {
+ m_guests.clear();
+ emit guestsChanged();
+ }
+}
+
+void BirthdayParty::replaceGuest(qsizetype index, Person *guest)
+{
+ if (m_guests.size() > index) {
+ m_guests[index] = guest;
+ emit guestsChanged();
+ }
+}
+
+void BirthdayParty::removeLastGuest()
+{
+ if (!m_guests.empty()) {
+ m_guests.removeLast();
+ emit guestsChanged();
+ }
+}
+
+void BirthdayParty::appendGuest(QQmlListProperty<Person> *list, Person *guest)
+{
+ static_cast<BirthdayParty *>(list->data)->appendGuest(guest);
+}
+
+void BirthdayParty::clearGuests(QQmlListProperty<Person> *list)
+{
+ static_cast<BirthdayParty *>(list->data)->clearGuests();
+}
+
+void BirthdayParty::replaceGuest(QQmlListProperty<Person> *list, qsizetype index, Person *guest)
+{
+ static_cast<BirthdayParty *>(list->data)->replaceGuest(index, guest);
+}
+
+void BirthdayParty::removeLastGuest(QQmlListProperty<Person> *list)
+{
+ static_cast<BirthdayParty *>(list->data)->removeLastGuest();
+}
+
+Person *BirthdayParty::guest(QQmlListProperty<Person> *list, qsizetype index)
+{
+ return static_cast<BirthdayParty *>(list->data)->guest(index);
+}
+
+qsizetype BirthdayParty::guestCount(QQmlListProperty<Person> *list)
+{
+ return static_cast<BirthdayParty *>(list->data)->guestCount();
+}
diff --git a/examples/qml/referenceexamples/properties/birthdayparty.h b/examples/qml/tutorials/extending-qml-advanced/advanced1-Base-project/birthdayparty.h
index 239626da17..1a28ef2632 100644
--- a/examples/qml/referenceexamples/properties/birthdayparty.h
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced1-Base-project/birthdayparty.h
@@ -1,26 +1,19 @@
-// Copyright (C) 2021 The Qt Company Ltd.
+// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#ifndef BIRTHDAYPARTY_H
#define BIRTHDAYPARTY_H
+#include "person.h"
+
#include <QObject>
-#include <QList>
#include <QQmlListProperty>
-#include "person.h"
-// ![0]
class BirthdayParty : public QObject
{
Q_OBJECT
-// ![0]
-// ![1]
- Q_PROPERTY(Person *host READ host WRITE setHost)
-// ![1]
-// ![2]
- Q_PROPERTY(QQmlListProperty<Person> guests READ guests)
-// ![2]
-// ![3]
+ Q_PROPERTY(Person *host READ host WRITE setHost NOTIFY hostChanged FINAL)
+ Q_PROPERTY(QQmlListProperty<Person> guests READ guests NOTIFY guestsChanged FINAL)
QML_ELEMENT
public:
using QObject::QObject;
@@ -36,10 +29,14 @@ public:
void replaceGuest(qsizetype, Person *);
void removeLastGuest();
+signals:
+ void hostChanged();
+ void guestsChanged();
+
private:
static void appendGuest(QQmlListProperty<Person> *, Person *);
static qsizetype guestCount(QQmlListProperty<Person> *);
- static Person* guest(QQmlListProperty<Person> *, qsizetype);
+ static Person *guest(QQmlListProperty<Person> *, qsizetype);
static void clearGuests(QQmlListProperty<Person> *);
static void replaceGuest(QQmlListProperty<Person> *, qsizetype, Person *);
static void removeLastGuest(QQmlListProperty<Person> *);
@@ -47,6 +44,5 @@ private:
Person *m_host = nullptr;
QList<Person *> m_guests;
};
-// ![3]
#endif // BIRTHDAYPARTY_H
diff --git a/examples/qml/referenceexamples/methods/main.cpp b/examples/qml/tutorials/extending-qml-advanced/advanced1-Base-project/main.cpp
index dd9b03566b..eac94016d2 100644
--- a/examples/qml/referenceexamples/methods/main.cpp
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced1-Base-project/main.cpp
@@ -1,24 +1,27 @@
-// Copyright (C) 2021 The Qt Company Ltd.
+// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-#include <QCoreApplication>
-#include <QQmlEngine>
-#include <QQmlComponent>
-#include <QDebug>
#include "birthdayparty.h"
#include "person.h"
-int main(int argc, char ** argv)
+#include <QCoreApplication>
+#include <QDebug>
+#include <QQmlComponent>
+#include <QQmlEngine>
+
+int main(int argc, char **argv)
{
QCoreApplication app(argc, argv);
QQmlEngine engine;
- QQmlComponent component(&engine, QUrl("qrc:example.qml"));
- auto *party = qobject_cast<BirthdayParty *>(component.create());
+ QQmlComponent component(&engine);
+ component.loadFromModule("People", "Main");
+ std::unique_ptr<BirthdayParty> party{ qobject_cast<BirthdayParty *>(component.create()) };
if (party && party->host()) {
- qInfo() << party->host()->name() << "is having a birthday!"
- << "\nThey are inviting:";
+ qInfo() << party->host()->name()
+ << "is having a birthday!\n"
+ "They are inviting:";
for (qsizetype ii = 0; ii < party->guestCount(); ++ii)
qInfo() << " " << party->guest(ii)->name();
return EXIT_SUCCESS;
diff --git a/examples/qml/tutorials/extending-qml-advanced/advanced1-Base-project/person.cpp b/examples/qml/tutorials/extending-qml-advanced/advanced1-Base-project/person.cpp
new file mode 100644
index 0000000000..f8f4b1d2f4
--- /dev/null
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced1-Base-project/person.cpp
@@ -0,0 +1,30 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+#include "person.h"
+
+QString Person::name() const
+{
+ return m_name;
+}
+
+void Person::setName(const QString &name)
+{
+ if (m_name != name) {
+ m_name = name;
+ emit nameChanged();
+ }
+}
+
+int Person::shoeSize() const
+{
+ return m_shoeSize;
+}
+
+void Person::setShoeSize(int shoeSize)
+{
+ if (m_shoeSize != shoeSize) {
+ m_shoeSize = shoeSize;
+ emit shoeSizeChanged();
+ }
+}
diff --git a/examples/qml/referenceexamples/adding/person.h b/examples/qml/tutorials/extending-qml-advanced/advanced1-Base-project/person.h
index 867927ee2b..ded272626a 100644
--- a/examples/qml/referenceexamples/adding/person.h
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced1-Base-project/person.h
@@ -1,18 +1,17 @@
-// Copyright (C) 2021 The Qt Company Ltd.
+// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#ifndef PERSON_H
#define PERSON_H
-#include <QObject>
#include <QtQml/qqml.h>
+#include <QObject>
-//![0]
class Person : public QObject
{
Q_OBJECT
- Q_PROPERTY(QString name READ name WRITE setName)
- Q_PROPERTY(int shoeSize READ shoeSize WRITE setShoeSize)
+ Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged FINAL)
+ Q_PROPERTY(int shoeSize READ shoeSize WRITE setShoeSize NOTIFY shoeSizeChanged FINAL)
QML_ELEMENT
public:
using QObject::QObject;
@@ -23,10 +22,13 @@ public:
int shoeSize() const;
void setShoeSize(int);
+signals:
+ void nameChanged();
+ void shoeSizeChanged();
+
private:
QString m_name;
int m_shoeSize = 0;
};
-//![0]
#endif // PERSON_H
diff --git a/examples/qml/tutorials/extending-qml-advanced/advanced1-Base-project/qmldir.in b/examples/qml/tutorials/extending-qml-advanced/advanced1-Base-project/qmldir.in
new file mode 100644
index 0000000000..70cde3c958
--- /dev/null
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced1-Base-project/qmldir.in
@@ -0,0 +1,4 @@
+module People
+typeinfo birthdayparty.qmltypes
+prefer :/qt/qml/People/
+Main 254.0 Main.qml
diff --git a/examples/qml/referenceexamples/coercion/CMakeLists.txt b/examples/qml/tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion/CMakeLists.txt
index 495b266f2f..0267cf09b2 100644
--- a/examples/qml/referenceexamples/coercion/CMakeLists.txt
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion/CMakeLists.txt
@@ -4,15 +4,16 @@
cmake_minimum_required(VERSION 3.16)
project(coercion LANGUAGES CXX)
-set(CMAKE_AUTOMOC ON)
-
if(NOT DEFINED INSTALL_EXAMPLESDIR)
set(INSTALL_EXAMPLESDIR "examples")
endif()
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/qml/referenceexamples/coercion")
+set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/qml/tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion")
find_package(Qt6 REQUIRED COMPONENTS Core Qml)
+qt_standard_project_setup()
+
+qt_policy(SET QTP0001 NEW)
qt_add_executable(coercion
birthdayparty.cpp birthdayparty.h
@@ -32,8 +33,7 @@ target_link_libraries(coercion PUBLIC
qt_add_qml_module(coercion
URI People
- QML_FILES example.qml
- NO_RESOURCE_TARGET_PATH
+ QML_FILES Main.qml
)
install(TARGETS coercion
diff --git a/examples/qml/referenceexamples/coercion/example.qml b/examples/qml/tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion/Main.qml
index 99469bec57..1c3fe141ca 100644
--- a/examples/qml/referenceexamples/coercion/example.qml
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion/Main.qml
@@ -1,9 +1,8 @@
-// Copyright (C) 2017 The Qt Company Ltd.
+// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
import People
-// ![0]
BirthdayParty {
host: Boy {
name: "Bob Jones"
@@ -15,4 +14,3 @@ BirthdayParty {
Girl { name: "Anne Brown" }
]
}
-// ![0]
diff --git a/examples/qml/tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion/birthdayparty.cpp b/examples/qml/tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion/birthdayparty.cpp
new file mode 100644
index 0000000000..ad38f284e7
--- /dev/null
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion/birthdayparty.cpp
@@ -0,0 +1,99 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+#include "birthdayparty.h"
+
+Person *BirthdayParty::host() const
+{
+ return m_host;
+}
+
+void BirthdayParty::setHost(Person *host)
+{
+ if (m_host != host) {
+ m_host = host;
+ emit hostChanged();
+ }
+}
+
+QQmlListProperty<Person> BirthdayParty::guests()
+{
+ return { this,
+ this,
+ &BirthdayParty::appendGuest,
+ &BirthdayParty::guestCount,
+ &BirthdayParty::guest,
+ &BirthdayParty::clearGuests,
+ &BirthdayParty::replaceGuest,
+ &BirthdayParty::removeLastGuest };
+}
+
+void BirthdayParty::appendGuest(Person *guest)
+{
+ m_guests.append(guest);
+ emit guestsChanged();
+}
+
+qsizetype BirthdayParty::guestCount() const
+{
+ return m_guests.count();
+}
+
+Person *BirthdayParty::guest(qsizetype index) const
+{
+ return m_guests.at(index);
+}
+
+void BirthdayParty::clearGuests()
+{
+ if (!m_guests.empty()) {
+ m_guests.clear();
+ emit guestsChanged();
+ }
+}
+
+void BirthdayParty::replaceGuest(qsizetype index, Person *guest)
+{
+ if (m_guests.size() > index) {
+ m_guests[index] = guest;
+ emit guestsChanged();
+ }
+}
+
+void BirthdayParty::removeLastGuest()
+{
+ if (!m_guests.empty()) {
+ m_guests.removeLast();
+ emit guestsChanged();
+ }
+}
+
+void BirthdayParty::appendGuest(QQmlListProperty<Person> *list, Person *guest)
+{
+ static_cast<BirthdayParty *>(list->data)->appendGuest(guest);
+}
+
+void BirthdayParty::clearGuests(QQmlListProperty<Person> *list)
+{
+ static_cast<BirthdayParty *>(list->data)->clearGuests();
+}
+
+void BirthdayParty::replaceGuest(QQmlListProperty<Person> *list, qsizetype index, Person *guest)
+{
+ static_cast<BirthdayParty *>(list->data)->replaceGuest(index, guest);
+}
+
+void BirthdayParty::removeLastGuest(QQmlListProperty<Person> *list)
+{
+ static_cast<BirthdayParty *>(list->data)->removeLastGuest();
+}
+
+Person *BirthdayParty::guest(QQmlListProperty<Person> *list, qsizetype index)
+{
+ return static_cast<BirthdayParty *>(list->data)->guest(index);
+}
+
+qsizetype BirthdayParty::guestCount(QQmlListProperty<Person> *list)
+{
+ return static_cast<BirthdayParty *>(list->data)->guestCount();
+}
diff --git a/examples/qml/tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion/birthdayparty.h b/examples/qml/tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion/birthdayparty.h
new file mode 100644
index 0000000000..f9a5c126e3
--- /dev/null
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion/birthdayparty.h
@@ -0,0 +1,48 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+#ifndef BIRTHDAYPARTY_H
+#define BIRTHDAYPARTY_H
+
+#include "person.h"
+
+#include <QObject>
+#include <QQmlListProperty>
+
+class BirthdayParty : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(Person *host READ host WRITE setHost NOTIFY hostChanged FINAL)
+ Q_PROPERTY(QQmlListProperty<Person> guests READ guests NOTIFY guestsChanged FINAL)
+ QML_ELEMENT
+public:
+ using QObject::QObject;
+
+ Person *host() const;
+ void setHost(Person *);
+
+ QQmlListProperty<Person> guests();
+ void appendGuest(Person *);
+ qsizetype guestCount() const;
+ Person *guest(qsizetype) const;
+ void clearGuests();
+ void replaceGuest(qsizetype, Person *);
+ void removeLastGuest();
+
+signals:
+ void hostChanged();
+ void guestsChanged();
+
+private:
+ static void appendGuest(QQmlListProperty<Person> *list, Person *);
+ static qsizetype guestCount(QQmlListProperty<Person> *);
+ static Person *guest(QQmlListProperty<Person> *, qsizetype);
+ static void clearGuests(QQmlListProperty<Person> *);
+ static void replaceGuest(QQmlListProperty<Person> *, qsizetype, Person *);
+ static void removeLastGuest(QQmlListProperty<Person> *);
+
+ Person *m_host = nullptr;
+ QList<Person *> m_guests;
+};
+
+#endif // BIRTHDAYPARTY_H
diff --git a/examples/qml/referenceexamples/coercion/coercion.pro b/examples/qml/tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion/coercion.pro
index 225fd13e08..1ba8194965 100644
--- a/examples/qml/referenceexamples/coercion/coercion.pro
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion/coercion.pro
@@ -10,6 +10,3 @@ SOURCES += main.cpp \
HEADERS += person.h \
birthdayparty.h
RESOURCES += coercion.qrc
-
-target.path = $$[QT_INSTALL_EXAMPLES]/qml/referenceexamples/coercion
-INSTALLS += target
diff --git a/examples/qml/tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion/coercion.qrc b/examples/qml/tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion/coercion.qrc
new file mode 100644
index 0000000000..b1eeb489e2
--- /dev/null
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion/coercion.qrc
@@ -0,0 +1,6 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource prefix="/qt/qml/People/">
+ <file>Main.qml</file>
+ <file alias="qmldir">qmldir.in</file>
+</qresource>
+</RCC>
diff --git a/examples/qml/referenceexamples/coercion/main.cpp b/examples/qml/tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion/main.cpp
index 5bcd9681e3..fa26448f44 100644
--- a/examples/qml/referenceexamples/coercion/main.cpp
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion/main.cpp
@@ -1,20 +1,22 @@
-// Copyright (C) 2021 The Qt Company Ltd.
+// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-#include <QCoreApplication>
-#include <QQmlEngine>
-#include <QQmlComponent>
-#include <QDebug>
#include "birthdayparty.h"
#include "person.h"
-int main(int argc, char ** argv)
+#include <QCoreApplication>
+#include <QDebug>
+#include <QQmlComponent>
+#include <QQmlEngine>
+
+int main(int argc, char **argv)
{
QCoreApplication app(argc, argv);
QQmlEngine engine;
- QQmlComponent component(&engine, QUrl("qrc:example.qml"));
- auto *party = qobject_cast<BirthdayParty *>(component.create());
+ QQmlComponent component(&engine);
+ component.loadFromModule("People", "Main");
+ std::unique_ptr<BirthdayParty> party{ qobject_cast<BirthdayParty *>(component.create()) };
if (party && party->host()) {
qInfo() << party->host()->name() << "is having a birthday!";
diff --git a/examples/qml/tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion/person.cpp b/examples/qml/tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion/person.cpp
new file mode 100644
index 0000000000..f8f4b1d2f4
--- /dev/null
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion/person.cpp
@@ -0,0 +1,30 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+#include "person.h"
+
+QString Person::name() const
+{
+ return m_name;
+}
+
+void Person::setName(const QString &name)
+{
+ if (m_name != name) {
+ m_name = name;
+ emit nameChanged();
+ }
+}
+
+int Person::shoeSize() const
+{
+ return m_shoeSize;
+}
+
+void Person::setShoeSize(int shoeSize)
+{
+ if (m_shoeSize != shoeSize) {
+ m_shoeSize = shoeSize;
+ emit shoeSizeChanged();
+ }
+}
diff --git a/examples/qml/referenceexamples/coercion/person.h b/examples/qml/tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion/person.h
index ea9ff970b4..99fc9209ab 100644
--- a/examples/qml/referenceexamples/coercion/person.h
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion/person.h
@@ -1,21 +1,19 @@
-// Copyright (C) 2021 The Qt Company Ltd.
+// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#ifndef PERSON_H
#define PERSON_H
-#include <QObject>
#include <QtQml/qqml.h>
+#include <QObject>
class Person : public QObject
{
Q_OBJECT
- Q_PROPERTY(QString name READ name WRITE setName)
- Q_PROPERTY(int shoeSize READ shoeSize WRITE setShoeSize)
- //![0]
+ Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged FINAL)
+ Q_PROPERTY(int shoeSize READ shoeSize WRITE setShoeSize NOTIFY shoeSizeChanged FINAL)
QML_ELEMENT
QML_UNCREATABLE("Person is an abstract base class.")
- //![0]
public:
using QObject::QObject;
@@ -25,12 +23,15 @@ public:
int shoeSize() const;
void setShoeSize(int);
+signals:
+ void nameChanged();
+ void shoeSizeChanged();
+
private:
QString m_name;
int m_shoeSize = 0;
};
-// ![1]
class Boy : public Person
{
Q_OBJECT
@@ -39,7 +40,6 @@ public:
using Person::Person;
};
-//! [girl class]
class Girl : public Person
{
Q_OBJECT
@@ -47,8 +47,5 @@ class Girl : public Person
public:
using Person::Person;
};
-//! [girl class]
-
-// ![1]
#endif // PERSON_H
diff --git a/examples/qml/tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion/qmldir.in b/examples/qml/tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion/qmldir.in
new file mode 100644
index 0000000000..3ccd68f7cc
--- /dev/null
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion/qmldir.in
@@ -0,0 +1,4 @@
+module People
+typeinfo coercion.qmltypes
+prefer :/qt/qml/People/
+Main 254.0 Main.qml
diff --git a/examples/qml/referenceexamples/default/CMakeLists.txt b/examples/qml/tutorials/extending-qml-advanced/advanced3-Default-properties/CMakeLists.txt
index 681085f386..079d965280 100644
--- a/examples/qml/referenceexamples/default/CMakeLists.txt
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced3-Default-properties/CMakeLists.txt
@@ -4,15 +4,16 @@
cmake_minimum_required(VERSION 3.16)
project(default LANGUAGES CXX)
-set(CMAKE_AUTOMOC ON)
-
if(NOT DEFINED INSTALL_EXAMPLESDIR)
set(INSTALL_EXAMPLESDIR "examples")
endif()
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/qml/referenceexamples/default")
+set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/qml/tutorials/extending-qml-advanced/advanced3-Default-properties")
find_package(Qt6 REQUIRED COMPONENTS Core Qml)
+qt_standard_project_setup()
+
+qt_policy(SET QTP0001 NEW)
qt_add_executable(default
birthdayparty.cpp birthdayparty.h
@@ -32,8 +33,7 @@ target_link_libraries(default PUBLIC
qt_add_qml_module(default
URI People
- QML_FILES example.qml
- NO_RESOURCE_TARGET_PATH
+ QML_FILES Main.qml
)
install(TARGETS default
diff --git a/examples/qml/referenceexamples/default/example.qml b/examples/qml/tutorials/extending-qml-advanced/advanced3-Default-properties/Main.qml
index addc74dfb5..1070427cb0 100644
--- a/examples/qml/referenceexamples/default/example.qml
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced3-Default-properties/Main.qml
@@ -1,9 +1,8 @@
-// Copyright (C) 2017 The Qt Company Ltd.
+// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
import People
-// ![0]
BirthdayParty {
host: Boy {
name: "Bob Jones"
@@ -14,4 +13,3 @@ BirthdayParty {
Boy { name: "Jack Smith" }
Girl { name: "Anne Brown" }
}
-// ![0]
diff --git a/examples/qml/tutorials/extending-qml-advanced/advanced3-Default-properties/birthdayparty.cpp b/examples/qml/tutorials/extending-qml-advanced/advanced3-Default-properties/birthdayparty.cpp
new file mode 100644
index 0000000000..ad38f284e7
--- /dev/null
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced3-Default-properties/birthdayparty.cpp
@@ -0,0 +1,99 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+#include "birthdayparty.h"
+
+Person *BirthdayParty::host() const
+{
+ return m_host;
+}
+
+void BirthdayParty::setHost(Person *host)
+{
+ if (m_host != host) {
+ m_host = host;
+ emit hostChanged();
+ }
+}
+
+QQmlListProperty<Person> BirthdayParty::guests()
+{
+ return { this,
+ this,
+ &BirthdayParty::appendGuest,
+ &BirthdayParty::guestCount,
+ &BirthdayParty::guest,
+ &BirthdayParty::clearGuests,
+ &BirthdayParty::replaceGuest,
+ &BirthdayParty::removeLastGuest };
+}
+
+void BirthdayParty::appendGuest(Person *guest)
+{
+ m_guests.append(guest);
+ emit guestsChanged();
+}
+
+qsizetype BirthdayParty::guestCount() const
+{
+ return m_guests.count();
+}
+
+Person *BirthdayParty::guest(qsizetype index) const
+{
+ return m_guests.at(index);
+}
+
+void BirthdayParty::clearGuests()
+{
+ if (!m_guests.empty()) {
+ m_guests.clear();
+ emit guestsChanged();
+ }
+}
+
+void BirthdayParty::replaceGuest(qsizetype index, Person *guest)
+{
+ if (m_guests.size() > index) {
+ m_guests[index] = guest;
+ emit guestsChanged();
+ }
+}
+
+void BirthdayParty::removeLastGuest()
+{
+ if (!m_guests.empty()) {
+ m_guests.removeLast();
+ emit guestsChanged();
+ }
+}
+
+void BirthdayParty::appendGuest(QQmlListProperty<Person> *list, Person *guest)
+{
+ static_cast<BirthdayParty *>(list->data)->appendGuest(guest);
+}
+
+void BirthdayParty::clearGuests(QQmlListProperty<Person> *list)
+{
+ static_cast<BirthdayParty *>(list->data)->clearGuests();
+}
+
+void BirthdayParty::replaceGuest(QQmlListProperty<Person> *list, qsizetype index, Person *guest)
+{
+ static_cast<BirthdayParty *>(list->data)->replaceGuest(index, guest);
+}
+
+void BirthdayParty::removeLastGuest(QQmlListProperty<Person> *list)
+{
+ static_cast<BirthdayParty *>(list->data)->removeLastGuest();
+}
+
+Person *BirthdayParty::guest(QQmlListProperty<Person> *list, qsizetype index)
+{
+ return static_cast<BirthdayParty *>(list->data)->guest(index);
+}
+
+qsizetype BirthdayParty::guestCount(QQmlListProperty<Person> *list)
+{
+ return static_cast<BirthdayParty *>(list->data)->guestCount();
+}
diff --git a/examples/qml/tutorials/extending-qml-advanced/advanced3-Default-properties/birthdayparty.h b/examples/qml/tutorials/extending-qml-advanced/advanced3-Default-properties/birthdayparty.h
new file mode 100644
index 0000000000..4d7e61a487
--- /dev/null
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced3-Default-properties/birthdayparty.h
@@ -0,0 +1,49 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+#ifndef BIRTHDAYPARTY_H
+#define BIRTHDAYPARTY_H
+
+#include "person.h"
+
+#include <QObject>
+#include <QQmlListProperty>
+
+class BirthdayParty : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(Person *host READ host WRITE setHost NOTIFY hostChanged FINAL)
+ Q_PROPERTY(QQmlListProperty<Person> guests READ guests NOTIFY guestsChanged FINAL)
+ Q_CLASSINFO("DefaultProperty", "guests")
+ QML_ELEMENT
+public:
+ using QObject::QObject;
+
+ Person *host() const;
+ void setHost(Person *);
+
+ QQmlListProperty<Person> guests();
+ void appendGuest(Person *);
+ qsizetype guestCount() const;
+ Person *guest(qsizetype) const;
+ void clearGuests();
+ void replaceGuest(qsizetype, Person *);
+ void removeLastGuest();
+
+signals:
+ void hostChanged();
+ void guestsChanged();
+
+private:
+ static void appendGuest(QQmlListProperty<Person> *list, Person *);
+ static qsizetype guestCount(QQmlListProperty<Person> *);
+ static Person *guest(QQmlListProperty<Person> *, qsizetype);
+ static void clearGuests(QQmlListProperty<Person> *);
+ static void replaceGuest(QQmlListProperty<Person> *, qsizetype, Person *);
+ static void removeLastGuest(QQmlListProperty<Person> *);
+
+ Person *m_host = nullptr;
+ QList<Person *> m_guests;
+};
+
+#endif // BIRTHDAYPARTY_H
diff --git a/examples/qml/referenceexamples/default/default.pro b/examples/qml/tutorials/extending-qml-advanced/advanced3-Default-properties/default.pro
index f52f749ddd..65dd27213b 100644
--- a/examples/qml/referenceexamples/default/default.pro
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced3-Default-properties/default.pro
@@ -10,6 +10,3 @@ SOURCES += main.cpp \
HEADERS += person.h \
birthdayparty.h
RESOURCES += default.qrc
-
-target.path = $$[QT_INSTALL_EXAMPLES]/qml/referenceexamples/default
-INSTALLS += target
diff --git a/examples/qml/tutorials/extending-qml-advanced/advanced3-Default-properties/default.qrc b/examples/qml/tutorials/extending-qml-advanced/advanced3-Default-properties/default.qrc
new file mode 100644
index 0000000000..b1eeb489e2
--- /dev/null
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced3-Default-properties/default.qrc
@@ -0,0 +1,6 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource prefix="/qt/qml/People/">
+ <file>Main.qml</file>
+ <file alias="qmldir">qmldir.in</file>
+</qresource>
+</RCC>
diff --git a/examples/qml/referenceexamples/default/main.cpp b/examples/qml/tutorials/extending-qml-advanced/advanced3-Default-properties/main.cpp
index 5e7e711ada..fa26448f44 100644
--- a/examples/qml/referenceexamples/default/main.cpp
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced3-Default-properties/main.cpp
@@ -1,19 +1,22 @@
-// Copyright (C) 2017 The Qt Company Ltd.
+// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-#include <QCoreApplication>
-#include <QQmlEngine>
-#include <QQmlComponent>
-#include <QDebug>
+
#include "birthdayparty.h"
#include "person.h"
-int main(int argc, char ** argv)
+#include <QCoreApplication>
+#include <QDebug>
+#include <QQmlComponent>
+#include <QQmlEngine>
+
+int main(int argc, char **argv)
{
QCoreApplication app(argc, argv);
QQmlEngine engine;
- QQmlComponent component(&engine, QUrl("qrc:example.qml"));
- auto *party = qobject_cast<BirthdayParty *>(component.create());
+ QQmlComponent component(&engine);
+ component.loadFromModule("People", "Main");
+ std::unique_ptr<BirthdayParty> party{ qobject_cast<BirthdayParty *>(component.create()) };
if (party && party->host()) {
qInfo() << party->host()->name() << "is having a birthday!";
diff --git a/examples/qml/tutorials/extending-qml-advanced/advanced3-Default-properties/person.cpp b/examples/qml/tutorials/extending-qml-advanced/advanced3-Default-properties/person.cpp
new file mode 100644
index 0000000000..f8f4b1d2f4
--- /dev/null
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced3-Default-properties/person.cpp
@@ -0,0 +1,30 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+#include "person.h"
+
+QString Person::name() const
+{
+ return m_name;
+}
+
+void Person::setName(const QString &name)
+{
+ if (m_name != name) {
+ m_name = name;
+ emit nameChanged();
+ }
+}
+
+int Person::shoeSize() const
+{
+ return m_shoeSize;
+}
+
+void Person::setShoeSize(int shoeSize)
+{
+ if (m_shoeSize != shoeSize) {
+ m_shoeSize = shoeSize;
+ emit shoeSizeChanged();
+ }
+}
diff --git a/examples/qml/referenceexamples/default/person.h b/examples/qml/tutorials/extending-qml-advanced/advanced3-Default-properties/person.h
index 04ab53696d..99fc9209ab 100644
--- a/examples/qml/referenceexamples/default/person.h
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced3-Default-properties/person.h
@@ -1,18 +1,19 @@
-// Copyright (C) 2021 The Qt Company Ltd.
+// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#ifndef PERSON_H
#define PERSON_H
-#include <QObject>
#include <QtQml/qqml.h>
+#include <QObject>
class Person : public QObject
{
Q_OBJECT
- Q_PROPERTY(QString name READ name WRITE setName)
- Q_PROPERTY(int shoeSize READ shoeSize WRITE setShoeSize)
- QML_ANONYMOUS
+ Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged FINAL)
+ Q_PROPERTY(int shoeSize READ shoeSize WRITE setShoeSize NOTIFY shoeSizeChanged FINAL)
+ QML_ELEMENT
+ QML_UNCREATABLE("Person is an abstract base class.")
public:
using QObject::QObject;
@@ -21,6 +22,11 @@ public:
int shoeSize() const;
void setShoeSize(int);
+
+signals:
+ void nameChanged();
+ void shoeSizeChanged();
+
private:
QString m_name;
int m_shoeSize = 0;
diff --git a/examples/qml/tutorials/extending-qml-advanced/advanced3-Default-properties/qmldir.in b/examples/qml/tutorials/extending-qml-advanced/advanced3-Default-properties/qmldir.in
new file mode 100644
index 0000000000..da1b995d64
--- /dev/null
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced3-Default-properties/qmldir.in
@@ -0,0 +1,4 @@
+module People
+typeinfo default.qmltypes
+prefer :/qt/qml/People/
+Main 254.0 Main.qml
diff --git a/examples/qml/referenceexamples/grouped/CMakeLists.txt b/examples/qml/tutorials/extending-qml-advanced/advanced4-Grouped-properties/CMakeLists.txt
index b1c7587b58..89aff6402f 100644
--- a/examples/qml/referenceexamples/grouped/CMakeLists.txt
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced4-Grouped-properties/CMakeLists.txt
@@ -4,15 +4,16 @@
cmake_minimum_required(VERSION 3.16)
project(grouped LANGUAGES CXX)
-set(CMAKE_AUTOMOC ON)
-
if(NOT DEFINED INSTALL_EXAMPLESDIR)
set(INSTALL_EXAMPLESDIR "examples")
endif()
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/qml/referenceexamples/grouped")
+set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/qml/tutorials/extending-qml-advanced/advanced4-Grouped-properties")
+
+find_package(Qt6 REQUIRED COMPONENTS Core Qml Gui)
+qt_standard_project_setup()
-find_package(Qt6 REQUIRED COMPONENTS Core Gui Qml)
+qt_policy(SET QTP0001 NEW)
qt_add_executable(grouped
birthdayparty.cpp birthdayparty.h
@@ -27,14 +28,15 @@ set_target_properties(grouped PROPERTIES
target_link_libraries(grouped PUBLIC
Qt::Core
- Qt::Gui
Qt::Qml
+ Qt::Gui
)
qt_add_qml_module(grouped
URI People
- QML_FILES example.qml
- NO_RESOURCE_TARGET_PATH
+ QML_FILES Main.qml
+ DEPENDENCIES
+ QtQuick
)
install(TARGETS grouped
diff --git a/examples/qml/referenceexamples/grouped/example.qml b/examples/qml/tutorials/extending-qml-advanced/advanced4-Grouped-properties/Main.qml
index 31d122e647..27951b5ea8 100644
--- a/examples/qml/referenceexamples/grouped/example.qml
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced4-Grouped-properties/Main.qml
@@ -1,10 +1,9 @@
-// Copyright (C) 2017 The Qt Company Ltd.
+// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
import People
import QtQuick // For QColor
-// ![0]
BirthdayParty {
host: Boy {
name: "Bob Jones"
@@ -13,11 +12,8 @@ BirthdayParty {
Boy {
name: "Leo Hodges"
-//![grouped]
shoe { size: 10; color: "black"; brand: "Thebok"; price: 59.95 }
-//![grouped]
}
- // ![1]
Boy {
name: "Jack Smith"
shoe {
@@ -27,15 +23,11 @@ BirthdayParty {
price: 19.95
}
}
- // ![1]
Girl {
name: "Anne Brown"
-//![ungrouped]
shoe.size: 7
shoe.color: "red"
shoe.brand: "Job Macobs"
- shoe.price: 699.99
-//![ungrouped]
+ shoe.price: 99.99
}
}
-// ![0]
diff --git a/examples/qml/tutorials/extending-qml-advanced/advanced4-Grouped-properties/birthdayparty.cpp b/examples/qml/tutorials/extending-qml-advanced/advanced4-Grouped-properties/birthdayparty.cpp
new file mode 100644
index 0000000000..ad38f284e7
--- /dev/null
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced4-Grouped-properties/birthdayparty.cpp
@@ -0,0 +1,99 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+#include "birthdayparty.h"
+
+Person *BirthdayParty::host() const
+{
+ return m_host;
+}
+
+void BirthdayParty::setHost(Person *host)
+{
+ if (m_host != host) {
+ m_host = host;
+ emit hostChanged();
+ }
+}
+
+QQmlListProperty<Person> BirthdayParty::guests()
+{
+ return { this,
+ this,
+ &BirthdayParty::appendGuest,
+ &BirthdayParty::guestCount,
+ &BirthdayParty::guest,
+ &BirthdayParty::clearGuests,
+ &BirthdayParty::replaceGuest,
+ &BirthdayParty::removeLastGuest };
+}
+
+void BirthdayParty::appendGuest(Person *guest)
+{
+ m_guests.append(guest);
+ emit guestsChanged();
+}
+
+qsizetype BirthdayParty::guestCount() const
+{
+ return m_guests.count();
+}
+
+Person *BirthdayParty::guest(qsizetype index) const
+{
+ return m_guests.at(index);
+}
+
+void BirthdayParty::clearGuests()
+{
+ if (!m_guests.empty()) {
+ m_guests.clear();
+ emit guestsChanged();
+ }
+}
+
+void BirthdayParty::replaceGuest(qsizetype index, Person *guest)
+{
+ if (m_guests.size() > index) {
+ m_guests[index] = guest;
+ emit guestsChanged();
+ }
+}
+
+void BirthdayParty::removeLastGuest()
+{
+ if (!m_guests.empty()) {
+ m_guests.removeLast();
+ emit guestsChanged();
+ }
+}
+
+void BirthdayParty::appendGuest(QQmlListProperty<Person> *list, Person *guest)
+{
+ static_cast<BirthdayParty *>(list->data)->appendGuest(guest);
+}
+
+void BirthdayParty::clearGuests(QQmlListProperty<Person> *list)
+{
+ static_cast<BirthdayParty *>(list->data)->clearGuests();
+}
+
+void BirthdayParty::replaceGuest(QQmlListProperty<Person> *list, qsizetype index, Person *guest)
+{
+ static_cast<BirthdayParty *>(list->data)->replaceGuest(index, guest);
+}
+
+void BirthdayParty::removeLastGuest(QQmlListProperty<Person> *list)
+{
+ static_cast<BirthdayParty *>(list->data)->removeLastGuest();
+}
+
+Person *BirthdayParty::guest(QQmlListProperty<Person> *list, qsizetype index)
+{
+ return static_cast<BirthdayParty *>(list->data)->guest(index);
+}
+
+qsizetype BirthdayParty::guestCount(QQmlListProperty<Person> *list)
+{
+ return static_cast<BirthdayParty *>(list->data)->guestCount();
+}
diff --git a/examples/qml/tutorials/extending-qml-advanced/advanced4-Grouped-properties/birthdayparty.h b/examples/qml/tutorials/extending-qml-advanced/advanced4-Grouped-properties/birthdayparty.h
new file mode 100644
index 0000000000..4d7e61a487
--- /dev/null
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced4-Grouped-properties/birthdayparty.h
@@ -0,0 +1,49 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+#ifndef BIRTHDAYPARTY_H
+#define BIRTHDAYPARTY_H
+
+#include "person.h"
+
+#include <QObject>
+#include <QQmlListProperty>
+
+class BirthdayParty : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(Person *host READ host WRITE setHost NOTIFY hostChanged FINAL)
+ Q_PROPERTY(QQmlListProperty<Person> guests READ guests NOTIFY guestsChanged FINAL)
+ Q_CLASSINFO("DefaultProperty", "guests")
+ QML_ELEMENT
+public:
+ using QObject::QObject;
+
+ Person *host() const;
+ void setHost(Person *);
+
+ QQmlListProperty<Person> guests();
+ void appendGuest(Person *);
+ qsizetype guestCount() const;
+ Person *guest(qsizetype) const;
+ void clearGuests();
+ void replaceGuest(qsizetype, Person *);
+ void removeLastGuest();
+
+signals:
+ void hostChanged();
+ void guestsChanged();
+
+private:
+ static void appendGuest(QQmlListProperty<Person> *list, Person *);
+ static qsizetype guestCount(QQmlListProperty<Person> *);
+ static Person *guest(QQmlListProperty<Person> *, qsizetype);
+ static void clearGuests(QQmlListProperty<Person> *);
+ static void replaceGuest(QQmlListProperty<Person> *, qsizetype, Person *);
+ static void removeLastGuest(QQmlListProperty<Person> *);
+
+ Person *m_host = nullptr;
+ QList<Person *> m_guests;
+};
+
+#endif // BIRTHDAYPARTY_H
diff --git a/examples/qml/referenceexamples/grouped/grouped.pro b/examples/qml/tutorials/extending-qml-advanced/advanced4-Grouped-properties/grouped.pro
index 1513ac552d..52e2937edf 100644
--- a/examples/qml/referenceexamples/grouped/grouped.pro
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced4-Grouped-properties/grouped.pro
@@ -10,6 +10,3 @@ SOURCES += main.cpp \
HEADERS += person.h \
birthdayparty.h
RESOURCES += grouped.qrc
-
-target.path = $$[QT_INSTALL_EXAMPLES]/qml/referenceexamples/grouped
-INSTALLS += target
diff --git a/examples/qml/tutorials/extending-qml-advanced/advanced4-Grouped-properties/grouped.qrc b/examples/qml/tutorials/extending-qml-advanced/advanced4-Grouped-properties/grouped.qrc
new file mode 100644
index 0000000000..b1eeb489e2
--- /dev/null
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced4-Grouped-properties/grouped.qrc
@@ -0,0 +1,6 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource prefix="/qt/qml/People/">
+ <file>Main.qml</file>
+ <file alias="qmldir">qmldir.in</file>
+</qresource>
+</RCC>
diff --git a/examples/qml/referenceexamples/grouped/main.cpp b/examples/qml/tutorials/extending-qml-advanced/advanced4-Grouped-properties/main.cpp
index 16f17262a2..0721d496f0 100644
--- a/examples/qml/referenceexamples/grouped/main.cpp
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced4-Grouped-properties/main.cpp
@@ -1,19 +1,22 @@
-// Copyright (C) 2017 The Qt Company Ltd.
+// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-#include <QCoreApplication>
-#include <QQmlEngine>
-#include <QQmlComponent>
-#include <QDebug>
+
#include "birthdayparty.h"
#include "person.h"
-int main(int argc, char ** argv)
+#include <QCoreApplication>
+#include <QDebug>
+#include <QQmlComponent>
+#include <QQmlEngine>
+
+int main(int argc, char **argv)
{
QCoreApplication app(argc, argv);
QQmlEngine engine;
- QQmlComponent component(&engine, QUrl("qrc:example.qml"));
- auto *party = qobject_cast<BirthdayParty *>(component.create());
+ QQmlComponent component(&engine);
+ component.loadFromModule("People", "Main");
+ std::unique_ptr<BirthdayParty> party{ qobject_cast<BirthdayParty *>(component.create()) };
if (party && party->host()) {
qInfo() << party->host()->name() << "is having a birthday!";
diff --git a/examples/qml/tutorials/extending-qml-advanced/advanced4-Grouped-properties/person.cpp b/examples/qml/tutorials/extending-qml-advanced/advanced4-Grouped-properties/person.cpp
new file mode 100644
index 0000000000..fe3d19b58d
--- /dev/null
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced4-Grouped-properties/person.cpp
@@ -0,0 +1,87 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+#include "person.h"
+
+Person::Person(QObject *parent) : QObject(parent)
+{
+ m_shoe = new ShoeDescription(this);
+}
+
+int ShoeDescription::size() const
+{
+ return m_size;
+}
+
+void ShoeDescription::setSize(int size)
+{
+ if (m_size != size) {
+ m_size = size;
+ emit shoeChanged();
+ }
+}
+
+QColor ShoeDescription::color() const
+{
+ return m_color;
+}
+
+void ShoeDescription::setColor(const QColor &color)
+{
+ if (m_color != color) {
+ m_color = color;
+ emit shoeChanged();
+ }
+}
+
+QString ShoeDescription::brand() const
+{
+ return m_brand;
+}
+
+void ShoeDescription::setBrand(const QString &brand)
+{
+ if (m_brand != brand) {
+ m_brand = brand;
+ emit shoeChanged();
+ }
+}
+
+qreal ShoeDescription::price() const
+{
+ return m_price;
+}
+
+void ShoeDescription::setPrice(qreal price)
+{
+ if (m_price != price) {
+ m_price = price;
+ emit shoeChanged();
+ }
+}
+
+QString Person::name() const
+{
+ return m_name;
+}
+
+void Person::setName(const QString &name)
+{
+ if (m_name != name) {
+ m_name = name;
+ emit nameChanged();
+ }
+}
+
+ShoeDescription *Person::shoe() const
+{
+ return m_shoe;
+}
+
+void Person::setShoe(ShoeDescription *shoe)
+{
+ if (m_shoe != shoe) {
+ m_shoe = shoe;
+ emit shoeChanged();
+ }
+}
diff --git a/examples/qml/referenceexamples/binding/person.h b/examples/qml/tutorials/extending-qml-advanced/advanced4-Grouped-properties/person.h
index 8314348bdf..ecb4545097 100644
--- a/examples/qml/referenceexamples/binding/person.h
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced4-Grouped-properties/person.h
@@ -1,20 +1,20 @@
-// Copyright (C) 2021 The Qt Company Ltd.
+// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#ifndef PERSON_H
#define PERSON_H
-#include <QObject>
-#include <QColor>
#include <QtQml/qqml.h>
+#include <QColor>
+#include <QObject>
class ShoeDescription : public QObject
{
Q_OBJECT
- Q_PROPERTY(int size READ size WRITE setSize NOTIFY shoeChanged)
- Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY shoeChanged)
- Q_PROPERTY(QString brand READ brand WRITE setBrand NOTIFY shoeChanged)
- Q_PROPERTY(qreal price READ price WRITE setPrice NOTIFY shoeChanged)
+ Q_PROPERTY(int size READ size WRITE setSize NOTIFY shoeChanged FINAL)
+ Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY shoeChanged FINAL)
+ Q_PROPERTY(QString brand READ brand WRITE setBrand NOTIFY shoeChanged FINAL)
+ Q_PROPERTY(qreal price READ price WRITE setPrice NOTIFY shoeChanged FINAL)
QML_ANONYMOUS
public:
using QObject::QObject;
@@ -44,25 +44,28 @@ private:
class Person : public QObject
{
Q_OBJECT
- Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
-// ![0]
- Q_PROPERTY(ShoeDescription *shoe READ shoe CONSTANT)
-// ![0]
- QML_ANONYMOUS
+ Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged FINAL)
+ Q_PROPERTY(ShoeDescription *shoe READ shoe WRITE setShoe NOTIFY shoeChanged FINAL)
+ QML_ELEMENT
+ QML_UNCREATABLE("Person is an abstract base class.")
public:
using QObject::QObject;
+ Person(QObject *parent = nullptr);
+
QString name() const;
void setName(const QString &);
- ShoeDescription *shoe();
+ ShoeDescription *shoe() const;
+ void setShoe(ShoeDescription *shoe);
signals:
void nameChanged();
+ void shoeChanged();
private:
QString m_name;
- ShoeDescription m_shoe;
+ ShoeDescription *m_shoe = nullptr;
};
class Boy : public Person
diff --git a/examples/qml/tutorials/extending-qml-advanced/advanced4-Grouped-properties/qmldir.in b/examples/qml/tutorials/extending-qml-advanced/advanced4-Grouped-properties/qmldir.in
new file mode 100644
index 0000000000..2e634e41af
--- /dev/null
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced4-Grouped-properties/qmldir.in
@@ -0,0 +1,5 @@
+module People
+typeinfo grouped.qmltypes
+prefer :/qt/qml/People/
+Main 254.0 Main.qml
+depends QtQuick
diff --git a/examples/qml/referenceexamples/attached/CMakeLists.txt b/examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties/CMakeLists.txt
index ce4ff3e80f..ca062f4675 100644
--- a/examples/qml/referenceexamples/attached/CMakeLists.txt
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties/CMakeLists.txt
@@ -4,15 +4,16 @@
cmake_minimum_required(VERSION 3.16)
project(attached LANGUAGES CXX)
-set(CMAKE_AUTOMOC ON)
-
if(NOT DEFINED INSTALL_EXAMPLESDIR)
set(INSTALL_EXAMPLESDIR "examples")
endif()
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/qml/referenceexamples/attached")
+set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties")
+
+find_package(Qt6 REQUIRED COMPONENTS Core Qml Quick)
+qt_standard_project_setup()
-find_package(Qt6 REQUIRED COMPONENTS Core Gui Qml)
+qt_policy(SET QTP0001 NEW)
qt_add_executable(attached
birthdayparty.cpp birthdayparty.h
@@ -27,14 +28,15 @@ set_target_properties(attached PROPERTIES
target_link_libraries(attached PUBLIC
Qt::Core
- Qt::Gui
Qt::Qml
+ Qt::Quick
)
qt_add_qml_module(attached
URI People
- QML_FILES example.qml
- NO_RESOURCE_TARGET_PATH
+ QML_FILES Main.qml
+ DEPENDENCIES
+ QtQuick
)
install(TARGETS attached
diff --git a/examples/qml/referenceexamples/attached/example.qml b/examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties/Main.qml
index a4e675fe51..8175eae209 100644
--- a/examples/qml/referenceexamples/attached/example.qml
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties/Main.qml
@@ -1,32 +1,23 @@
-// Copyright (C) 2017 The Qt Company Ltd.
+// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
import People
import QtQuick // For QColor
-//! [begin]
BirthdayParty {
-//! [begin]
-
-//! [rsvp]
Boy {
name: "Robert Campbell"
- BirthdayParty.rsvp: "2009-07-01"
+ BirthdayParty.rsvp: Date.fromLocaleString(Qt.locale(), "2023-03-01", "yyyy-MM-dd")
}
-//! [rsvp]
- // ![1]
+
Boy {
name: "Leo Hodges"
shoe { size: 10; color: "black"; brand: "Reebok"; price: 59.95 }
-
- BirthdayParty.rsvp: "2009-07-06"
+ BirthdayParty.rsvp: Date.fromLocaleString(Qt.locale(), "2023-03-03", "yyyy-MM-dd")
}
- // ![1]
+
host: Boy {
name: "Jack Smith"
shoe { size: 8; color: "blue"; brand: "Puma"; price: 19.95 }
}
-//! [end]
}
-//! [end]
-
diff --git a/examples/qml/referenceexamples/attached/attached.pro b/examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties/attached.pro
index 8c66b189f7..ab154eb48b 100644
--- a/examples/qml/referenceexamples/attached/attached.pro
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties/attached.pro
@@ -1,6 +1,6 @@
-QT += qml
-CONFIG += qmltypes
+QT += qml quick
+CONFIG += qmltypes
QML_IMPORT_NAME = People
QML_IMPORT_MAJOR_VERSION = 1
@@ -10,6 +10,3 @@ SOURCES += main.cpp \
HEADERS += person.h \
birthdayparty.h
RESOURCES += attached.qrc
-
-target.path = $$[QT_INSTALL_EXAMPLES]/qml/referenceexamples/attached
-INSTALLS += target
diff --git a/examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties/attached.qrc b/examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties/attached.qrc
new file mode 100644
index 0000000000..b1eeb489e2
--- /dev/null
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties/attached.qrc
@@ -0,0 +1,6 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource prefix="/qt/qml/People/">
+ <file>Main.qml</file>
+ <file alias="qmldir">qmldir.in</file>
+</qresource>
+</RCC>
diff --git a/examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties/birthdayparty.cpp b/examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties/birthdayparty.cpp
new file mode 100644
index 0000000000..0379a7accf
--- /dev/null
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties/birthdayparty.cpp
@@ -0,0 +1,117 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+#include "birthdayparty.h"
+
+QDate BirthdayPartyAttached::rsvp() const
+{
+ return m_rsvp;
+}
+
+void BirthdayPartyAttached::setRsvp(QDate rsvpDate)
+{
+ if (m_rsvp != rsvpDate) {
+ m_rsvp = rsvpDate;
+ emit rsvpChanged();
+ }
+}
+
+Person *BirthdayParty::host() const
+{
+ return m_host;
+}
+
+void BirthdayParty::setHost(Person *host)
+{
+ if (m_host != host) {
+ m_host = host;
+ emit hostChanged();
+ }
+}
+
+QQmlListProperty<Person> BirthdayParty::guests()
+{
+ return { this,
+ this,
+ &BirthdayParty::appendGuest,
+ &BirthdayParty::guestCount,
+ &BirthdayParty::guest,
+ &BirthdayParty::clearGuests,
+ &BirthdayParty::replaceGuest,
+ &BirthdayParty::removeLastGuest };
+}
+
+void BirthdayParty::appendGuest(Person *guest)
+{
+ m_guests.append(guest);
+ emit guestsChanged();
+}
+
+qsizetype BirthdayParty::guestCount() const
+{
+ return m_guests.count();
+}
+
+Person *BirthdayParty::guest(qsizetype index) const
+{
+ return m_guests.at(index);
+}
+
+void BirthdayParty::clearGuests()
+{
+ if (!m_guests.empty()) {
+ m_guests.clear();
+ emit guestsChanged();
+ }
+}
+
+void BirthdayParty::replaceGuest(qsizetype index, Person *guest)
+{
+ if (m_guests.size() > index) {
+ m_guests[index] = guest;
+ emit guestsChanged();
+ }
+}
+
+void BirthdayParty::removeLastGuest()
+{
+ if (!m_guests.empty()) {
+ m_guests.removeLast();
+ emit guestsChanged();
+ }
+}
+
+void BirthdayParty::appendGuest(QQmlListProperty<Person> *list, Person *guest)
+{
+ static_cast<BirthdayParty *>(list->data)->appendGuest(guest);
+}
+
+void BirthdayParty::clearGuests(QQmlListProperty<Person> *list)
+{
+ static_cast<BirthdayParty *>(list->data)->clearGuests();
+}
+
+void BirthdayParty::replaceGuest(QQmlListProperty<Person> *list, qsizetype index, Person *guest)
+{
+ static_cast<BirthdayParty *>(list->data)->replaceGuest(index, guest);
+}
+
+void BirthdayParty::removeLastGuest(QQmlListProperty<Person> *list)
+{
+ static_cast<BirthdayParty *>(list->data)->removeLastGuest();
+}
+
+Person *BirthdayParty::guest(QQmlListProperty<Person> *list, qsizetype index)
+{
+ return static_cast<BirthdayParty *>(list->data)->guest(index);
+}
+
+qsizetype BirthdayParty::guestCount(QQmlListProperty<Person> *list)
+{
+ return static_cast<BirthdayParty *>(list->data)->guestCount();
+}
+
+BirthdayPartyAttached *BirthdayParty::qmlAttachedProperties(QObject *object)
+{
+ return new BirthdayPartyAttached(object);
+}
diff --git a/examples/qml/referenceexamples/binding/birthdayparty.h b/examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties/birthdayparty.h
index 3b4c92cae3..1b2503895a 100644
--- a/examples/qml/referenceexamples/binding/birthdayparty.h
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties/birthdayparty.h
@@ -1,19 +1,19 @@
-// Copyright (C) 2021 The Qt Company Ltd.
+// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#ifndef BIRTHDAYPARTY_H
#define BIRTHDAYPARTY_H
-#include <QObject>
+#include "person.h"
+
#include <QDate>
-#include <QDebug>
+#include <QObject>
#include <qqml.h>
-#include "person.h"
class BirthdayPartyAttached : public QObject
{
Q_OBJECT
- Q_PROPERTY(QDate rsvp READ rsvp WRITE setRsvp NOTIFY rsvpChanged)
+ Q_PROPERTY(QDate rsvp READ rsvp WRITE setRsvp NOTIFY rsvpChanged FINAL)
QML_ANONYMOUS
public:
using QObject::QObject;
@@ -31,14 +31,12 @@ private:
class BirthdayParty : public QObject
{
Q_OBJECT
-// ![0]
- Q_PROPERTY(Person *host READ host WRITE setHost NOTIFY hostChanged)
-// ![0]
- Q_PROPERTY(QQmlListProperty<Person> guests READ guests)
- Q_PROPERTY(QString announcement READ announcement WRITE setAnnouncement)
+ Q_PROPERTY(Person *host READ host WRITE setHost NOTIFY hostChanged FINAL)
+ Q_PROPERTY(QQmlListProperty<Person> guests READ guests NOTIFY guestsChanged FINAL)
Q_CLASSINFO("DefaultProperty", "guests")
QML_ELEMENT
QML_ATTACHED(BirthdayPartyAttached)
+
public:
using QObject::QObject;
@@ -46,20 +44,27 @@ public:
void setHost(Person *);
QQmlListProperty<Person> guests();
+ void appendGuest(Person *);
qsizetype guestCount() const;
Person *guest(qsizetype) const;
-
- QString announcement() const;
- void setAnnouncement(const QString &);
+ void clearGuests();
+ void replaceGuest(qsizetype, Person *);
+ void removeLastGuest();
static BirthdayPartyAttached *qmlAttachedProperties(QObject *);
- void startParty();
signals:
- void partyStarted(QTime time);
void hostChanged();
+ void guestsChanged();
private:
+ static void appendGuest(QQmlListProperty<Person> *list, Person *);
+ static qsizetype guestCount(QQmlListProperty<Person> *);
+ static Person *guest(QQmlListProperty<Person> *, qsizetype);
+ static void clearGuests(QQmlListProperty<Person> *);
+ static void replaceGuest(QQmlListProperty<Person> *, qsizetype, Person *);
+ static void removeLastGuest(QQmlListProperty<Person> *);
+
Person *m_host = nullptr;
QList<Person *> m_guests;
};
diff --git a/examples/qml/referenceexamples/attached/main.cpp b/examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties/main.cpp
index cfe0a1b9b2..09691f3b6a 100644
--- a/examples/qml/referenceexamples/attached/main.cpp
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties/main.cpp
@@ -1,20 +1,22 @@
-// Copyright (C) 2021 The Qt Company Ltd.
+// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-#include <QCoreApplication>
-#include <QQmlEngine>
-#include <QQmlComponent>
-#include <QDebug>
#include "birthdayparty.h"
#include "person.h"
-int main(int argc, char ** argv)
+#include <QCoreApplication>
+#include <QDebug>
+#include <QQmlComponent>
+#include <QQmlEngine>
+
+int main(int argc, char **argv)
{
QCoreApplication app(argc, argv);
QQmlEngine engine;
- QQmlComponent component(&engine, QUrl("qrc:example.qml"));
- auto *party = qobject_cast<BirthdayParty *>(component.create());
+ QQmlComponent component(&engine);
+ component.loadFromModule("People", "Main");
+ std::unique_ptr<BirthdayParty> party{ qobject_cast<BirthdayParty *>(component.create()) };
if (party && party->host()) {
qInfo() << party->host()->name() << "is having a birthday!";
@@ -27,13 +29,11 @@ int main(int argc, char ** argv)
for (qsizetype ii = 0; ii < party->guestCount(); ++ii) {
Person *guest = party->guest(ii);
- //! [query rsvp]
QDate rsvpDate;
QObject *attached = qmlAttachedPropertiesObject<BirthdayParty>(guest, false);
if (attached)
rsvpDate = attached->property("rsvp").toDate();
- //! [query rsvp]
if (rsvpDate.isNull())
qInfo() << " " << guest->name() << "RSVP date: Hasn't RSVP'd";
else
diff --git a/examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties/person.cpp b/examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties/person.cpp
new file mode 100644
index 0000000000..fe3d19b58d
--- /dev/null
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties/person.cpp
@@ -0,0 +1,87 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+#include "person.h"
+
+Person::Person(QObject *parent) : QObject(parent)
+{
+ m_shoe = new ShoeDescription(this);
+}
+
+int ShoeDescription::size() const
+{
+ return m_size;
+}
+
+void ShoeDescription::setSize(int size)
+{
+ if (m_size != size) {
+ m_size = size;
+ emit shoeChanged();
+ }
+}
+
+QColor ShoeDescription::color() const
+{
+ return m_color;
+}
+
+void ShoeDescription::setColor(const QColor &color)
+{
+ if (m_color != color) {
+ m_color = color;
+ emit shoeChanged();
+ }
+}
+
+QString ShoeDescription::brand() const
+{
+ return m_brand;
+}
+
+void ShoeDescription::setBrand(const QString &brand)
+{
+ if (m_brand != brand) {
+ m_brand = brand;
+ emit shoeChanged();
+ }
+}
+
+qreal ShoeDescription::price() const
+{
+ return m_price;
+}
+
+void ShoeDescription::setPrice(qreal price)
+{
+ if (m_price != price) {
+ m_price = price;
+ emit shoeChanged();
+ }
+}
+
+QString Person::name() const
+{
+ return m_name;
+}
+
+void Person::setName(const QString &name)
+{
+ if (m_name != name) {
+ m_name = name;
+ emit nameChanged();
+ }
+}
+
+ShoeDescription *Person::shoe() const
+{
+ return m_shoe;
+}
+
+void Person::setShoe(ShoeDescription *shoe)
+{
+ if (m_shoe != shoe) {
+ m_shoe = shoe;
+ emit shoeChanged();
+ }
+}
diff --git a/examples/qml/referenceexamples/attached/person.h b/examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties/person.h
index 9c617ee9ab..ecb4545097 100644
--- a/examples/qml/referenceexamples/attached/person.h
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties/person.h
@@ -1,20 +1,20 @@
-// Copyright (C) 2021 The Qt Company Ltd.
+// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#ifndef PERSON_H
#define PERSON_H
-#include <QObject>
-#include <QColor>
#include <QtQml/qqml.h>
+#include <QColor>
+#include <QObject>
class ShoeDescription : public QObject
{
Q_OBJECT
- Q_PROPERTY(int size READ size WRITE setSize)
- Q_PROPERTY(QColor color READ color WRITE setColor)
- Q_PROPERTY(QString brand READ brand WRITE setBrand)
- Q_PROPERTY(qreal price READ price WRITE setPrice)
+ Q_PROPERTY(int size READ size WRITE setSize NOTIFY shoeChanged FINAL)
+ Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY shoeChanged FINAL)
+ Q_PROPERTY(QString brand READ brand WRITE setBrand NOTIFY shoeChanged FINAL)
+ Q_PROPERTY(qreal price READ price WRITE setPrice NOTIFY shoeChanged FINAL)
QML_ANONYMOUS
public:
using QObject::QObject;
@@ -31,6 +31,9 @@ public:
qreal price() const;
void setPrice(qreal);
+signals:
+ void shoeChanged();
+
private:
int m_size = 0;
QColor m_color;
@@ -41,19 +44,28 @@ private:
class Person : public QObject
{
Q_OBJECT
- Q_PROPERTY(QString name READ name WRITE setName)
- Q_PROPERTY(ShoeDescription *shoe READ shoe)
- QML_ANONYMOUS
+ Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged FINAL)
+ Q_PROPERTY(ShoeDescription *shoe READ shoe WRITE setShoe NOTIFY shoeChanged FINAL)
+ QML_ELEMENT
+ QML_UNCREATABLE("Person is an abstract base class.")
public:
using QObject::QObject;
+ Person(QObject *parent = nullptr);
+
QString name() const;
void setName(const QString &);
- ShoeDescription *shoe();
+ ShoeDescription *shoe() const;
+ void setShoe(ShoeDescription *shoe);
+
+signals:
+ void nameChanged();
+ void shoeChanged();
+
private:
QString m_name;
- ShoeDescription m_shoe;
+ ShoeDescription *m_shoe = nullptr;
};
class Boy : public Person
diff --git a/examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties/qmldir.in b/examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties/qmldir.in
new file mode 100644
index 0000000000..1038298c01
--- /dev/null
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties/qmldir.in
@@ -0,0 +1,5 @@
+module People
+typeinfo attached.qmltypes
+prefer :/qt/qml/People/
+Main 254.0 Main.qml
+depends QtQuick
diff --git a/examples/qml/referenceexamples/valuesource/CMakeLists.txt b/examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/CMakeLists.txt
index 266bb2b754..67ca56153c 100644
--- a/examples/qml/referenceexamples/valuesource/CMakeLists.txt
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/CMakeLists.txt
@@ -4,15 +4,16 @@
cmake_minimum_required(VERSION 3.16)
project(valuesource LANGUAGES CXX)
-set(CMAKE_AUTOMOC ON)
-
if(NOT DEFINED INSTALL_EXAMPLESDIR)
set(INSTALL_EXAMPLESDIR "examples")
endif()
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/qml/referenceexamples/valuesource")
+set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source")
+
+find_package(Qt6 REQUIRED COMPONENTS Core Qml Quick)
+qt_standard_project_setup()
-find_package(Qt6 REQUIRED COMPONENTS Core Gui Qml)
+qt_policy(SET QTP0001 NEW)
qt_add_executable(valuesource
birthdayparty.cpp birthdayparty.h
@@ -28,14 +29,15 @@ set_target_properties(valuesource PROPERTIES
target_link_libraries(valuesource PUBLIC
Qt::Core
- Qt::Gui
Qt::Qml
+ Qt::Quick
)
qt_add_qml_module(valuesource
URI People
- QML_FILES example.qml
- NO_RESOURCE_TARGET_PATH
+ QML_FILES Main.qml
+ DEPENDENCIES
+ QtQuick
)
install(TARGETS valuesource
diff --git a/examples/qml/referenceexamples/valuesource/example.qml b/examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/Main.qml
index b6efe211c1..7f79d0a0c4 100644
--- a/examples/qml/referenceexamples/valuesource/example.qml
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/Main.qml
@@ -1,13 +1,14 @@
-// Copyright (C) 2017 The Qt Company Ltd.
+// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
import People
import QtQuick // For QColor
-// ![0]
BirthdayParty {
- HappyBirthdaySong on announcement { name: "Bob Jones" }
-// ![0]
+ id: party
+ HappyBirthdaySong on announcement {
+ name: party.host.name
+ }
onPartyStarted: (time) => { console.log("This party started rockin' at " + time); }
@@ -19,7 +20,7 @@ BirthdayParty {
Boy {
name: "Leo Hodges"
- BirthdayParty.rsvp: "2009-07-06"
+ BirthdayParty.rsvp: Date.fromLocaleString(Qt.locale(), "2023-03-01", "yyyy-MM-dd")
shoe { size: 10; color: "black"; brand: "Reebok"; price: 59.95 }
}
Boy {
@@ -28,13 +29,10 @@ BirthdayParty {
}
Girl {
name: "Anne Brown"
- BirthdayParty.rsvp: "2009-07-01"
+ BirthdayParty.rsvp: Date.fromLocaleString(Qt.locale(), "2023-03-03", "yyyy-MM-dd")
shoe.size: 7
shoe.color: "red"
shoe.brand: "Marc Jacobs"
- shoe.price: 699.99
+ shoe.price: 99.99
}
-
-// ![1]
}
-// ![1]
diff --git a/examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/birthdayparty.cpp b/examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/birthdayparty.cpp
new file mode 100644
index 0000000000..b14f7ef315
--- /dev/null
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/birthdayparty.cpp
@@ -0,0 +1,137 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+#include "birthdayparty.h"
+
+QDate BirthdayPartyAttached::rsvp() const
+{
+ return m_rsvp;
+}
+
+void BirthdayPartyAttached::setRsvp(QDate rsvpDate)
+{
+ if (m_rsvp != rsvpDate) {
+ m_rsvp = rsvpDate;
+ emit rsvpChanged();
+ }
+}
+
+Person *BirthdayParty::host() const
+{
+ return m_host;
+}
+
+void BirthdayParty::setHost(Person *host)
+{
+ if (m_host != host) {
+ m_host = host;
+ emit hostChanged();
+ }
+}
+
+QQmlListProperty<Person> BirthdayParty::guests()
+{
+ return { this,
+ this,
+ &BirthdayParty::appendGuest,
+ &BirthdayParty::guestCount,
+ &BirthdayParty::guest,
+ &BirthdayParty::clearGuests,
+ &BirthdayParty::replaceGuest,
+ &BirthdayParty::removeLastGuest };
+}
+
+void BirthdayParty::appendGuest(Person *guest)
+{
+ m_guests.append(guest);
+ emit guestsChanged();
+}
+
+qsizetype BirthdayParty::guestCount() const
+{
+ return m_guests.count();
+}
+
+Person *BirthdayParty::guest(qsizetype index) const
+{
+ return m_guests.at(index);
+}
+
+void BirthdayParty::clearGuests()
+{
+ if (!m_guests.empty()) {
+ m_guests.clear();
+ emit guestsChanged();
+ }
+}
+
+void BirthdayParty::replaceGuest(qsizetype index, Person *guest)
+{
+ if (m_guests.size() > index) {
+ m_guests[index] = guest;
+ emit guestsChanged();
+ }
+}
+
+void BirthdayParty::removeLastGuest()
+{
+ if (!m_guests.empty()) {
+ m_guests.removeLast();
+ emit guestsChanged();
+ }
+}
+
+void BirthdayParty::appendGuest(QQmlListProperty<Person> *list, Person *guest)
+{
+ static_cast<BirthdayParty *>(list->data)->appendGuest(guest);
+}
+
+void BirthdayParty::clearGuests(QQmlListProperty<Person> *list)
+{
+ static_cast<BirthdayParty *>(list->data)->clearGuests();
+}
+
+void BirthdayParty::replaceGuest(QQmlListProperty<Person> *list, qsizetype index, Person *guest)
+{
+ static_cast<BirthdayParty *>(list->data)->replaceGuest(index, guest);
+}
+
+void BirthdayParty::removeLastGuest(QQmlListProperty<Person> *list)
+{
+ static_cast<BirthdayParty *>(list->data)->removeLastGuest();
+}
+
+Person *BirthdayParty::guest(QQmlListProperty<Person> *list, qsizetype index)
+{
+ return static_cast<BirthdayParty *>(list->data)->guest(index);
+}
+
+qsizetype BirthdayParty::guestCount(QQmlListProperty<Person> *list)
+{
+ return static_cast<BirthdayParty *>(list->data)->guestCount();
+}
+
+void BirthdayParty::startParty()
+{
+ QDateTime time = QDateTime::currentDateTime();
+ emit partyStarted(time);
+}
+
+QString BirthdayParty::announcement() const
+{
+ return m_announcement;
+}
+
+void BirthdayParty::setAnnouncement(const QString &announcement)
+{
+ if (m_announcement != announcement) {
+ m_announcement = announcement;
+ emit announcementChanged();
+ }
+ qInfo().noquote() << announcement;
+}
+
+BirthdayPartyAttached *BirthdayParty::qmlAttachedProperties(QObject *object)
+{
+ return new BirthdayPartyAttached(object);
+}
diff --git a/examples/qml/referenceexamples/valuesource/birthdayparty.h b/examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/birthdayparty.h
index 922dac838b..799a3fa969 100644
--- a/examples/qml/referenceexamples/valuesource/birthdayparty.h
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/birthdayparty.h
@@ -1,19 +1,21 @@
-// Copyright (C) 2021 The Qt Company Ltd.
+// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#ifndef BIRTHDAYPARTY_H
#define BIRTHDAYPARTY_H
-#include <QObject>
+#include "person.h"
+
#include <QDate>
#include <QDebug>
+#include <QObject>
+#include <QQmlListProperty>
#include <qqml.h>
-#include "person.h"
class BirthdayPartyAttached : public QObject
{
Q_OBJECT
- Q_PROPERTY(QDate rsvp READ rsvp WRITE setRsvp)
+ Q_PROPERTY(QDate rsvp READ rsvp WRITE setRsvp NOTIFY rsvpChanged FINAL)
QML_ANONYMOUS
public:
using QObject::QObject;
@@ -21,6 +23,9 @@ public:
QDate rsvp() const;
void setRsvp(QDate);
+signals:
+ void rsvpChanged();
+
private:
QDate m_rsvp;
};
@@ -28,11 +33,9 @@ private:
class BirthdayParty : public QObject
{
Q_OBJECT
- Q_PROPERTY(Person *host READ host WRITE setHost)
- Q_PROPERTY(QQmlListProperty<Person> guests READ guests)
-// ![0]
- Q_PROPERTY(QString announcement READ announcement WRITE setAnnouncement)
-// ![0]
+ Q_PROPERTY(Person *host READ host WRITE setHost NOTIFY hostChanged FINAL)
+ Q_PROPERTY(QQmlListProperty<Person> guests READ guests NOTIFY guestsChanged FINAL)
+ Q_PROPERTY(QString announcement READ announcement WRITE setAnnouncement NOTIFY announcementChanged FINAL)
Q_CLASSINFO("DefaultProperty", "guests")
QML_ELEMENT
QML_ATTACHED(BirthdayPartyAttached)
@@ -42,23 +45,38 @@ public:
Person *host() const;
void setHost(Person *);
+ QString announcement() const;
+ void setAnnouncement(const QString &);
+
QQmlListProperty<Person> guests();
+ void appendGuest(Person *);
qsizetype guestCount() const;
Person *guest(qsizetype) const;
-
- QString announcement() const;
- void setAnnouncement(const QString &);
+ void clearGuests();
+ void replaceGuest(qsizetype, Person *);
+ void removeLastGuest();
static BirthdayPartyAttached *qmlAttachedProperties(QObject *);
void startParty();
signals:
- void partyStarted(QTime time);
+ void hostChanged();
+ void guestsChanged();
+ void partyStarted(QDateTime time);
+ void announcementChanged();
private:
+ static void appendGuest(QQmlListProperty<Person> *, Person *);
+ static qsizetype guestCount(QQmlListProperty<Person> *);
+ static Person *guest(QQmlListProperty<Person> *, qsizetype);
+ static void clearGuests(QQmlListProperty<Person> *);
+ static void replaceGuest(QQmlListProperty<Person> *, qsizetype, Person *);
+ static void removeLastGuest(QQmlListProperty<Person> *);
+
Person *m_host = nullptr;
QList<Person *> m_guests;
+ QString m_announcement;
};
#endif // BIRTHDAYPARTY_H
diff --git a/examples/qml/referenceexamples/binding/happybirthdaysong.cpp b/examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/happybirthdaysong.cpp
index cf71a7f213..7a756a4a71 100644
--- a/examples/qml/referenceexamples/binding/happybirthdaysong.cpp
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/happybirthdaysong.cpp
@@ -1,19 +1,20 @@
-// Copyright (C) 2017 The Qt Company Ltd.
+// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
#include "happybirthdaysong.h"
+
#include <QTimer>
-HappyBirthdaySong::HappyBirthdaySong(QObject *parent) :
- QObject(parent)
+HappyBirthdaySong::HappyBirthdaySong(QObject *parent) : QObject(parent)
{
auto *timer = new QTimer(this);
QObject::connect(timer, &QTimer::timeout, this, &HappyBirthdaySong::advance);
timer->start(1000);
}
-void HappyBirthdaySong::setTarget(const QQmlProperty &p)
+void HappyBirthdaySong::setTarget(const QQmlProperty &target)
{
- m_target = p;
+ m_target = target;
}
QString HappyBirthdaySong::name() const
@@ -23,10 +24,10 @@ QString HappyBirthdaySong::name() const
void HappyBirthdaySong::setName(const QString &name)
{
- if (m_name == name)
- return;
-
- m_name = name;
+ if (m_name != name) {
+ m_name = name;
+ emit nameChanged();
+ }
m_lyrics.clear();
m_lyrics << "Happy birthday to you,";
@@ -34,8 +35,6 @@ void HappyBirthdaySong::setName(const QString &name)
m_lyrics << "Happy birthday dear " + m_name + ",";
m_lyrics << "Happy birthday to you!";
m_lyrics << "";
-
- emit nameChanged();
}
void HappyBirthdaySong::advance()
@@ -44,4 +43,3 @@ void HappyBirthdaySong::advance()
m_target.write(m_lyrics.at(m_line));
}
-
diff --git a/examples/qml/referenceexamples/binding/happybirthdaysong.h b/examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/happybirthdaysong.h
index 8705abfa83..13907d5485 100644
--- a/examples/qml/referenceexamples/binding/happybirthdaysong.h
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/happybirthdaysong.h
@@ -1,20 +1,19 @@
-// Copyright (C) 2017 The Qt Company Ltd.
+// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
#ifndef HAPPYBIRTHDAYSONG_H
#define HAPPYBIRTHDAYSONG_H
-#include <QQmlPropertyValueSource>
#include <QQmlProperty>
+#include <QQmlPropertyValueSource>
#include <qqml.h>
-
#include <QStringList>
-#include <qqml.h>
class HappyBirthdaySong : public QObject, public QQmlPropertyValueSource
{
Q_OBJECT
- Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
Q_INTERFACES(QQmlPropertyValueSource)
+ Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged FINAL)
QML_ELEMENT
public:
explicit HappyBirthdaySong(QObject *parent = nullptr);
@@ -24,11 +23,12 @@ public:
QString name() const;
void setName(const QString &);
+signals:
+ void nameChanged();
+
private slots:
void advance();
-signals:
- void nameChanged();
private:
qsizetype m_line = -1;
QStringList m_lyrics;
@@ -37,4 +37,3 @@ private:
};
#endif // HAPPYBIRTHDAYSONG_H
-
diff --git a/examples/qml/referenceexamples/valuesource/main.cpp b/examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/main.cpp
index 716deeccda..6d67b6179e 100644
--- a/examples/qml/referenceexamples/valuesource/main.cpp
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/main.cpp
@@ -1,20 +1,22 @@
-// Copyright (C) 2017 The Qt Company Ltd.
+// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-#include <QCoreApplication>
-#include <QQmlEngine>
-#include <QQmlComponent>
-#include <QDebug>
+
#include "birthdayparty.h"
-#include "happybirthdaysong.h"
#include "person.h"
-int main(int argc, char ** argv)
+#include <QCoreApplication>
+#include <QDebug>
+#include <QQmlComponent>
+#include <QQmlEngine>
+
+int main(int argc, char **argv)
{
QCoreApplication app(argc, argv);
QQmlEngine engine;
- QQmlComponent component(&engine, QUrl("qrc:example.qml"));
- auto *party = qobject_cast<BirthdayParty *>(component.create());
+ QQmlComponent component(&engine);
+ component.loadFromModule("People", "Main");
+ std::unique_ptr<BirthdayParty> party{ qobject_cast<BirthdayParty *>(component.create()) };
if (party && party->host()) {
qInfo() << party->host()->name() << "is having a birthday!";
@@ -28,8 +30,7 @@ int main(int argc, char ** argv)
Person *guest = party->guest(ii);
QDate rsvpDate;
- QObject *attached =
- qmlAttachedPropertiesObject<BirthdayParty>(guest, false);
+ QObject *attached = qmlAttachedPropertiesObject<BirthdayParty>(guest, false);
if (attached)
rsvpDate = attached->property("rsvp").toDate();
diff --git a/examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/person.cpp b/examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/person.cpp
new file mode 100644
index 0000000000..fe3d19b58d
--- /dev/null
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/person.cpp
@@ -0,0 +1,87 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+#include "person.h"
+
+Person::Person(QObject *parent) : QObject(parent)
+{
+ m_shoe = new ShoeDescription(this);
+}
+
+int ShoeDescription::size() const
+{
+ return m_size;
+}
+
+void ShoeDescription::setSize(int size)
+{
+ if (m_size != size) {
+ m_size = size;
+ emit shoeChanged();
+ }
+}
+
+QColor ShoeDescription::color() const
+{
+ return m_color;
+}
+
+void ShoeDescription::setColor(const QColor &color)
+{
+ if (m_color != color) {
+ m_color = color;
+ emit shoeChanged();
+ }
+}
+
+QString ShoeDescription::brand() const
+{
+ return m_brand;
+}
+
+void ShoeDescription::setBrand(const QString &brand)
+{
+ if (m_brand != brand) {
+ m_brand = brand;
+ emit shoeChanged();
+ }
+}
+
+qreal ShoeDescription::price() const
+{
+ return m_price;
+}
+
+void ShoeDescription::setPrice(qreal price)
+{
+ if (m_price != price) {
+ m_price = price;
+ emit shoeChanged();
+ }
+}
+
+QString Person::name() const
+{
+ return m_name;
+}
+
+void Person::setName(const QString &name)
+{
+ if (m_name != name) {
+ m_name = name;
+ emit nameChanged();
+ }
+}
+
+ShoeDescription *Person::shoe() const
+{
+ return m_shoe;
+}
+
+void Person::setShoe(ShoeDescription *shoe)
+{
+ if (m_shoe != shoe) {
+ m_shoe = shoe;
+ emit shoeChanged();
+ }
+}
diff --git a/examples/qml/referenceexamples/signal/person.h b/examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/person.h
index 9c617ee9ab..ecb4545097 100644
--- a/examples/qml/referenceexamples/signal/person.h
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/person.h
@@ -1,20 +1,20 @@
-// Copyright (C) 2021 The Qt Company Ltd.
+// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#ifndef PERSON_H
#define PERSON_H
-#include <QObject>
-#include <QColor>
#include <QtQml/qqml.h>
+#include <QColor>
+#include <QObject>
class ShoeDescription : public QObject
{
Q_OBJECT
- Q_PROPERTY(int size READ size WRITE setSize)
- Q_PROPERTY(QColor color READ color WRITE setColor)
- Q_PROPERTY(QString brand READ brand WRITE setBrand)
- Q_PROPERTY(qreal price READ price WRITE setPrice)
+ Q_PROPERTY(int size READ size WRITE setSize NOTIFY shoeChanged FINAL)
+ Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY shoeChanged FINAL)
+ Q_PROPERTY(QString brand READ brand WRITE setBrand NOTIFY shoeChanged FINAL)
+ Q_PROPERTY(qreal price READ price WRITE setPrice NOTIFY shoeChanged FINAL)
QML_ANONYMOUS
public:
using QObject::QObject;
@@ -31,6 +31,9 @@ public:
qreal price() const;
void setPrice(qreal);
+signals:
+ void shoeChanged();
+
private:
int m_size = 0;
QColor m_color;
@@ -41,19 +44,28 @@ private:
class Person : public QObject
{
Q_OBJECT
- Q_PROPERTY(QString name READ name WRITE setName)
- Q_PROPERTY(ShoeDescription *shoe READ shoe)
- QML_ANONYMOUS
+ Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged FINAL)
+ Q_PROPERTY(ShoeDescription *shoe READ shoe WRITE setShoe NOTIFY shoeChanged FINAL)
+ QML_ELEMENT
+ QML_UNCREATABLE("Person is an abstract base class.")
public:
using QObject::QObject;
+ Person(QObject *parent = nullptr);
+
QString name() const;
void setName(const QString &);
- ShoeDescription *shoe();
+ ShoeDescription *shoe() const;
+ void setShoe(ShoeDescription *shoe);
+
+signals:
+ void nameChanged();
+ void shoeChanged();
+
private:
QString m_name;
- ShoeDescription m_shoe;
+ ShoeDescription *m_shoe = nullptr;
};
class Boy : public Person
diff --git a/examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/qmldir.in b/examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/qmldir.in
new file mode 100644
index 0000000000..4c63c729d6
--- /dev/null
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/qmldir.in
@@ -0,0 +1,5 @@
+module People
+typeinfo valuesource.qmltypes
+prefer :/qt/qml/People/
+Main 254.0 Main.qml
+depends QtQuick
diff --git a/examples/qml/referenceexamples/valuesource/valuesource.pro b/examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/valuesource.pro
index 6d29cf1b70..c55299cecf 100644
--- a/examples/qml/referenceexamples/valuesource/valuesource.pro
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/valuesource.pro
@@ -1,4 +1,4 @@
-QT += qml
+QT += qml quick
CONFIG += qmltypes
QML_IMPORT_NAME = People
@@ -12,6 +12,3 @@ HEADERS += person.h \
birthdayparty.h \
happybirthdaysong.h
RESOURCES += valuesource.qrc
-
-target.path = $$[QT_INSTALL_EXAMPLES]/qml/referenceexamples/valuesource
-INSTALLS += target
diff --git a/examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/valuesource.qrc b/examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/valuesource.qrc
new file mode 100644
index 0000000000..b1eeb489e2
--- /dev/null
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/valuesource.qrc
@@ -0,0 +1,6 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource prefix="/qt/qml/People/">
+ <file>Main.qml</file>
+ <file alias="qmldir">qmldir.in</file>
+</qresource>
+</RCC>
diff --git a/examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/CMakeLists.txt b/examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/CMakeLists.txt
new file mode 100644
index 0000000000..3769b887c0
--- /dev/null
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/CMakeLists.txt
@@ -0,0 +1,60 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+cmake_minimum_required(VERSION 3.16)
+project(foreign LANGUAGES CXX)
+
+if(NOT DEFINED INSTALL_EXAMPLESDIR)
+ set(INSTALL_EXAMPLESDIR "examples")
+endif()
+
+set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/qml/tutorials/extending-qml-advanced/advanced7-Extension-objects")
+
+find_package(Qt6 REQUIRED COMPONENTS Core Qml Quick Gui)
+qt_standard_project_setup()
+
+qt_policy(SET QTP0001 NEW)
+
+add_subdirectory(library/)
+
+qt_add_executable(foreign
+ birthdayparty.cpp
+ birthdayparty.h
+ foreigndisplay.h
+ happybirthdaysong.cpp
+ happybirthdaysong.h
+ person.cpp
+ person.h
+ main.cpp
+)
+
+target_link_libraries(foreign PUBLIC
+ Qt::Core
+ Qt::Qml
+ Qt::Gui
+ library
+)
+
+set_target_properties(foreign PROPERTIES
+ WIN32_EXECUTABLE TRUE
+ MACOSX_BUNDLE TRUE
+)
+
+target_include_directories(foreign PUBLIC
+ "${PROJECT_BINARY_DIR}"
+ "${PROJECT_SOURCE_DIR}/library"
+)
+
+qt_add_qml_module(foreign
+ URI People
+ QML_FILES Main.qml
+ SOURCES foreigndisplay.h
+ DEPENDENCIES
+ QtQuick
+)
+
+install(TARGETS foreign
+ RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
+ LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+)
diff --git a/examples/qml/referenceexamples/binding/example.qml b/examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/Main.qml
index 262d667903..988bea49f8 100644
--- a/examples/qml/referenceexamples/binding/example.qml
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/Main.qml
@@ -1,26 +1,31 @@
-// Copyright (C) 2017 The Qt Company Ltd.
+// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
import People
import QtQuick // For QColor
-// ![0]
BirthdayParty {
- id: theParty
+ id: party
+ HappyBirthdaySong on announcement {
+ name: party.host.name
+ }
+
+ display: ThirdPartyDisplay {
+ foregroundColor: "black"
+ backgroundColor: "white"
+ }
+
+ onPartyStarted: (time) => { console.log("This party started rockin' at " + time); }
- HappyBirthdaySong on announcement { name: theParty.host.name }
host: Boy {
name: "Bob Jones"
shoe { size: 12; color: "white"; brand: "Nike"; price: 90.0 }
}
-// ![0]
- onPartyStarted: (time) => { console.log("This party started rockin' at " + time); }
-
Boy {
name: "Leo Hodges"
- BirthdayParty.rsvp: "2009-07-06"
+ BirthdayParty.rsvp: Date.fromLocaleString(Qt.locale(), "2023-03-01", "yyyy-MM-dd")
shoe { size: 10; color: "black"; brand: "Reebok"; price: 59.95 }
}
Boy {
@@ -29,13 +34,10 @@ BirthdayParty {
}
Girl {
name: "Anne Brown"
- BirthdayParty.rsvp: "2009-07-01"
+ BirthdayParty.rsvp: Date.fromLocaleString(Qt.locale(), "2023-03-03", "yyyy-MM-dd")
shoe.size: 7
shoe.color: "red"
shoe.brand: "Marc Jacobs"
- shoe.price: 699.99
+ shoe.price: 99.99
}
-
-// ![1]
}
-// ![1]
diff --git a/examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/application.pro b/examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/application.pro
new file mode 100644
index 0000000000..b53397d49c
--- /dev/null
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/application.pro
@@ -0,0 +1,26 @@
+TEMPLATE = app
+
+CONFIG += console
+
+QT += core qml
+
+DEPENDPATH += library
+INCLUDEPATH += library
+LIBS += -Llibrary/ -llibrary
+
+SOURCES += \
+ birthdayparty.cpp \
+ happybirthdaysong.cpp \
+ main.cpp \
+ person.cpp
+HEADERS += \
+ birthdayparty.h \
+ foreigndisplay.h \
+ happybirthdaysong.h \
+ person.h
+
+CONFIG += qmltypes
+QML_IMPORT_NAME = People
+QML_IMPORT_MAJOR_VERSION = 1
+
+RESOURCES += foreign.qrc
diff --git a/examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/birthdayparty.cpp b/examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/birthdayparty.cpp
new file mode 100644
index 0000000000..7a9debe195
--- /dev/null
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/birthdayparty.cpp
@@ -0,0 +1,150 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+#include "birthdayparty.h"
+
+QDate BirthdayPartyAttached::rsvp() const
+{
+ return m_rsvp;
+}
+
+void BirthdayPartyAttached::setRsvp(QDate rsvpDate)
+{
+ if (m_rsvp != rsvpDate) {
+ m_rsvp = rsvpDate;
+ emit rsvpChanged();
+ }
+}
+
+Person *BirthdayParty::host() const
+{
+ return m_host;
+}
+
+void BirthdayParty::setHost(Person *host)
+{
+ if (m_host != host) {
+ m_host = host;
+ emit hostChanged();
+ }
+}
+
+QQmlListProperty<Person> BirthdayParty::guests()
+{
+ return { this,
+ this,
+ &BirthdayParty::appendGuest,
+ &BirthdayParty::guestCount,
+ &BirthdayParty::guest,
+ &BirthdayParty::clearGuests,
+ &BirthdayParty::replaceGuest,
+ &BirthdayParty::removeLastGuest };
+}
+
+void BirthdayParty::appendGuest(Person *guest)
+{
+ m_guests.append(guest);
+ emit guestsChanged();
+}
+
+qsizetype BirthdayParty::guestCount() const
+{
+ return m_guests.count();
+}
+
+Person *BirthdayParty::guest(qsizetype index) const
+{
+ return m_guests.at(index);
+}
+
+void BirthdayParty::clearGuests()
+{
+ if (!m_guests.empty()) {
+ m_guests.clear();
+ emit guestsChanged();
+ }
+}
+
+void BirthdayParty::replaceGuest(qsizetype index, Person *guest)
+{
+ if (m_guests.size() > index) {
+ m_guests[index] = guest;
+ emit guestsChanged();
+ }
+}
+
+void BirthdayParty::removeLastGuest()
+{
+ if (!m_guests.empty()) {
+ m_guests.removeLast();
+ emit guestsChanged();
+ }
+}
+
+void BirthdayParty::appendGuest(QQmlListProperty<Person> *list, Person *guest)
+{
+ static_cast<BirthdayParty *>(list->data)->appendGuest(guest);
+}
+
+void BirthdayParty::clearGuests(QQmlListProperty<Person> *list)
+{
+ static_cast<BirthdayParty *>(list->data)->clearGuests();
+}
+
+void BirthdayParty::replaceGuest(QQmlListProperty<Person> *list, qsizetype index, Person *guest)
+{
+ static_cast<BirthdayParty *>(list->data)->replaceGuest(index, guest);
+}
+
+void BirthdayParty::removeLastGuest(QQmlListProperty<Person> *list)
+{
+ static_cast<BirthdayParty *>(list->data)->removeLastGuest();
+}
+
+Person *BirthdayParty::guest(QQmlListProperty<Person> *list, qsizetype index)
+{
+ return static_cast<BirthdayParty *>(list->data)->guest(index);
+}
+
+qsizetype BirthdayParty::guestCount(QQmlListProperty<Person> *list)
+{
+ return static_cast<BirthdayParty *>(list->data)->guestCount();
+}
+
+void BirthdayParty::startParty()
+{
+ QDateTime time = QDateTime::currentDateTime();
+ emit partyStarted(time);
+}
+
+QString BirthdayParty::announcement() const
+{
+ return m_announcement;
+}
+
+void BirthdayParty::setAnnouncement(const QString &announcement)
+{
+ if (m_announcement != announcement) {
+ m_announcement = announcement;
+ emit announcementChanged();
+ }
+ m_display->setContent(announcement);
+}
+
+ThirdPartyDisplay *BirthdayParty::display() const
+{
+ return m_display;
+}
+
+void BirthdayParty::setDisplay(ThirdPartyDisplay *display)
+{
+ if (m_display != display) {
+ m_display = display;
+ emit displayChanged();
+ }
+}
+
+BirthdayPartyAttached *BirthdayParty::qmlAttachedProperties(QObject *object)
+{
+ return new BirthdayPartyAttached(object);
+}
diff --git a/examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/birthdayparty.h b/examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/birthdayparty.h
new file mode 100644
index 0000000000..59c53f2484
--- /dev/null
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/birthdayparty.h
@@ -0,0 +1,90 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+#ifndef BIRTHDAYPARTY_H
+#define BIRTHDAYPARTY_H
+
+#include "person.h"
+#include "ThirdPartyDisplay.h"
+
+#include <QDate>
+#include <QDebug>
+#include <QObject>
+#include <qqml.h>
+
+#include <memory>
+
+class BirthdayPartyAttached : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(QDate rsvp READ rsvp WRITE setRsvp NOTIFY rsvpChanged FINAL)
+ QML_ANONYMOUS
+public:
+ using QObject::QObject;
+
+ QDate rsvp() const;
+ void setRsvp(QDate);
+
+signals:
+ void rsvpChanged();
+
+private:
+ QDate m_rsvp;
+};
+
+class BirthdayParty : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(Person *host READ host WRITE setHost NOTIFY hostChanged FINAL)
+ Q_PROPERTY(QQmlListProperty<Person> guests READ guests NOTIFY guestsChanged FINAL)
+ Q_PROPERTY(QString announcement READ announcement WRITE setAnnouncement NOTIFY announcementChanged FINAL)
+ Q_PROPERTY(ThirdPartyDisplay *display READ display WRITE setDisplay NOTIFY displayChanged FINAL)
+ Q_CLASSINFO("DefaultProperty", "guests")
+ QML_ELEMENT
+ QML_ATTACHED(BirthdayPartyAttached)
+public:
+ using QObject::QObject;
+
+ Person *host() const;
+ void setHost(Person *);
+
+ QQmlListProperty<Person> guests();
+ void appendGuest(Person *);
+ qsizetype guestCount() const;
+ Person *guest(qsizetype) const;
+ void clearGuests();
+ void replaceGuest(qsizetype, Person *);
+ void removeLastGuest();
+
+ QString announcement() const;
+ void setAnnouncement(const QString &);
+
+ ThirdPartyDisplay *display() const;
+ void setDisplay(ThirdPartyDisplay *);
+
+ static BirthdayPartyAttached *qmlAttachedProperties(QObject *);
+
+ void startParty();
+
+signals:
+ void hostChanged();
+ void guestsChanged();
+ void partyStarted(QDateTime time);
+ void announcementChanged();
+ void displayChanged();
+
+private:
+ static void appendGuest(QQmlListProperty<Person> *, Person *);
+ static qsizetype guestCount(QQmlListProperty<Person> *);
+ static Person *guest(QQmlListProperty<Person> *, qsizetype);
+ static void clearGuests(QQmlListProperty<Person> *);
+ static void replaceGuest(QQmlListProperty<Person> *, qsizetype, Person *);
+ static void removeLastGuest(QQmlListProperty<Person> *);
+
+ Person *m_host = nullptr;
+ QList<Person *> m_guests;
+ QString m_announcement;
+ ThirdPartyDisplay *m_display = nullptr;
+};
+
+#endif // BIRTHDAYPARTY_H
diff --git a/examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/foreign.pro b/examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/foreign.pro
new file mode 100644
index 0000000000..b637cb0840
--- /dev/null
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/foreign.pro
@@ -0,0 +1,7 @@
+TEMPLATE = subdirs
+
+SUBDIRS = \
+ application.pro \
+ library
+
+application.depends = library
diff --git a/examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/foreign.qrc b/examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/foreign.qrc
new file mode 100644
index 0000000000..b1eeb489e2
--- /dev/null
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/foreign.qrc
@@ -0,0 +1,6 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource prefix="/qt/qml/People/">
+ <file>Main.qml</file>
+ <file alias="qmldir">qmldir.in</file>
+</qresource>
+</RCC>
diff --git a/examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/foreigndisplay.h b/examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/foreigndisplay.h
new file mode 100644
index 0000000000..ee42ca965c
--- /dev/null
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/foreigndisplay.h
@@ -0,0 +1,20 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+#ifndef FOREIGNDISPLAY_H
+#define FOREIGNDISPLAY_H
+
+#include "ThirdPartyDisplay.h"
+
+#include <QColor>
+#include <QObject>
+#include <qqml.h>
+
+class ForeignDisplay : public QObject
+{
+ Q_OBJECT
+ QML_NAMED_ELEMENT(ThirdPartyDisplay)
+ QML_FOREIGN(ThirdPartyDisplay)
+};
+
+#endif // FOREIGNDISPLAY_H
diff --git a/examples/qml/referenceexamples/valuesource/happybirthdaysong.cpp b/examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/happybirthdaysong.cpp
index e9a8c13ae9..7a756a4a71 100644
--- a/examples/qml/referenceexamples/valuesource/happybirthdaysong.cpp
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/happybirthdaysong.cpp
@@ -1,20 +1,20 @@
-// Copyright (C) 2021 The Qt Company Ltd.
+// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include "happybirthdaysong.h"
+
#include <QTimer>
-HappyBirthdaySong::HappyBirthdaySong(QObject *parent) :
- QObject(parent)
+HappyBirthdaySong::HappyBirthdaySong(QObject *parent) : QObject(parent)
{
auto *timer = new QTimer(this);
QObject::connect(timer, &QTimer::timeout, this, &HappyBirthdaySong::advance);
timer->start(1000);
}
-void HappyBirthdaySong::setTarget(const QQmlProperty &p)
+void HappyBirthdaySong::setTarget(const QQmlProperty &target)
{
- m_target = p;
+ m_target = target;
}
QString HappyBirthdaySong::name() const
@@ -24,7 +24,10 @@ QString HappyBirthdaySong::name() const
void HappyBirthdaySong::setName(const QString &name)
{
- m_name = name;
+ if (m_name != name) {
+ m_name = name;
+ emit nameChanged();
+ }
m_lyrics.clear();
m_lyrics << "Happy birthday to you,";
@@ -40,4 +43,3 @@ void HappyBirthdaySong::advance()
m_target.write(m_lyrics.at(m_line));
}
-
diff --git a/examples/qml/referenceexamples/valuesource/happybirthdaysong.h b/examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/happybirthdaysong.h
index 1aad47232a..f87521a760 100644
--- a/examples/qml/referenceexamples/valuesource/happybirthdaysong.h
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/happybirthdaysong.h
@@ -1,4 +1,4 @@
-// Copyright (C) 2021 The Qt Company Ltd.
+// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#ifndef HAPPYBIRTHDAYSONG_H
@@ -7,27 +7,25 @@
#include <QQmlPropertyValueSource>
#include <QQmlProperty>
#include <qqml.h>
-
#include <QStringList>
-// ![0]
class HappyBirthdaySong : public QObject, public QQmlPropertyValueSource
{
Q_OBJECT
Q_INTERFACES(QQmlPropertyValueSource)
-// ![0]
- Q_PROPERTY(QString name READ name WRITE setName)
-// ![1]
+ Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged FINAL)
QML_ELEMENT
public:
explicit HappyBirthdaySong(QObject *parent = nullptr);
void setTarget(const QQmlProperty &) override;
-// ![1]
QString name() const;
void setName(const QString &);
+signals:
+ void nameChanged();
+
private slots:
void advance();
@@ -36,9 +34,6 @@ private:
QStringList m_lyrics;
QQmlProperty m_target;
QString m_name;
-// ![2]
};
-// ![2]
#endif // HAPPYBIRTHDAYSONG_H
-
diff --git a/examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/library/CMakeLists.txt b/examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/library/CMakeLists.txt
new file mode 100644
index 0000000000..5b4528a340
--- /dev/null
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/library/CMakeLists.txt
@@ -0,0 +1,17 @@
+# Copyright (C) 2023 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+cmake_minimum_required(VERSION 3.16)
+
+project(library)
+
+add_library(library ThirdPartyDisplay.cpp ThirdPartyDisplay.h)
+
+qt_extract_metatypes(library)
+
+target_link_libraries(library PUBLIC
+ Qt::Core
+ Qt::Qml
+ Qt::Quick
+ Qt::Gui
+)
diff --git a/examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/library/ThirdPartyDisplay.cpp b/examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/library/ThirdPartyDisplay.cpp
new file mode 100644
index 0000000000..5fc4eb2e8f
--- /dev/null
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/library/ThirdPartyDisplay.cpp
@@ -0,0 +1,45 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+#include "ThirdPartyDisplay.h"
+#include <QDebug>
+
+const QString &ThirdPartyDisplay::content() const
+{
+ return m_content;
+}
+
+void ThirdPartyDisplay::setContent(const QString &content)
+{
+ if (m_content != content) {
+ m_content = content;
+ emit contentChanged();
+ }
+ qInfo() << QStringLiteral("[Fancy ThirdPartyDisplay] ") + content;
+}
+
+QColor ThirdPartyDisplay::foregroundColor() const
+{
+ return m_foregroundColor;
+}
+
+void ThirdPartyDisplay::setForegroundColor(QColor color)
+{
+ if (m_foregroundColor != color) {
+ m_foregroundColor = color;
+ emit colorsChanged();
+ }
+}
+
+QColor ThirdPartyDisplay::backgroundColor() const
+{
+ return m_backgroundColor;
+}
+
+void ThirdPartyDisplay::setBackgroundColor(QColor color)
+{
+ if (m_backgroundColor != color) {
+ m_backgroundColor = color;
+ emit colorsChanged();
+ }
+}
diff --git a/examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/library/ThirdPartyDisplay.h b/examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/library/ThirdPartyDisplay.h
new file mode 100644
index 0000000000..525c9f72cf
--- /dev/null
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/library/ThirdPartyDisplay.h
@@ -0,0 +1,36 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+#ifndef THIRDPARTYDISPLAY_H
+#define THIRDPARTYDISPLAY_H
+
+#include <QColor>
+#include <QObject>
+
+class Q_DECL_EXPORT ThirdPartyDisplay : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(QString content READ content WRITE setContent NOTIFY contentChanged FINAL)
+ Q_PROPERTY(QColor foregroundColor READ foregroundColor WRITE setForegroundColor NOTIFY colorsChanged FINAL)
+ Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY colorsChanged FINAL)
+public:
+ const QString &content() const;
+ void setContent(const QString &content);
+
+ QColor foregroundColor() const;
+ void setForegroundColor(QColor);
+
+ QColor backgroundColor() const;
+ void setBackgroundColor(QColor);
+
+signals:
+ void contentChanged();
+ void colorsChanged();
+
+private:
+ QString m_content;
+ QColor m_foregroundColor;
+ QColor m_backgroundColor;
+};
+
+#endif // THIRDPARTYDISPLAY_H
diff --git a/examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/library/library.pro b/examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/library/library.pro
new file mode 100644
index 0000000000..f7009c46c9
--- /dev/null
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/library/library.pro
@@ -0,0 +1,8 @@
+TEMPLATE = lib
+
+CONFIG += static
+
+SOURCES += ThirdPartyDisplay.cpp
+HEADERS += ThirdPartyDisplay.h
+
+QT += core qml gui
diff --git a/examples/qml/referenceexamples/binding/main.cpp b/examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/main.cpp
index 716deeccda..9c6f6bcc2f 100644
--- a/examples/qml/referenceexamples/binding/main.cpp
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/main.cpp
@@ -1,20 +1,23 @@
-// Copyright (C) 2017 The Qt Company Ltd.
+// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+#include "birthdayparty.h"
+#include "person.h"
+
#include <QCoreApplication>
#include <QQmlEngine>
#include <QQmlComponent>
#include <QDebug>
-#include "birthdayparty.h"
-#include "happybirthdaysong.h"
-#include "person.h"
+#include <QFile>
-int main(int argc, char ** argv)
+int main(int argc, char **argv)
{
QCoreApplication app(argc, argv);
QQmlEngine engine;
- QQmlComponent component(&engine, QUrl("qrc:example.qml"));
- auto *party = qobject_cast<BirthdayParty *>(component.create());
+ QQmlComponent component(&engine);
+ component.loadFromModule("People", "Main");
+ std::unique_ptr<BirthdayParty> party{ qobject_cast<BirthdayParty *>(component.create()) };
if (party && party->host()) {
qInfo() << party->host()->name() << "is having a birthday!";
@@ -28,8 +31,7 @@ int main(int argc, char ** argv)
Person *guest = party->guest(ii);
QDate rsvpDate;
- QObject *attached =
- qmlAttachedPropertiesObject<BirthdayParty>(guest, false);
+ QObject *attached = qmlAttachedPropertiesObject<BirthdayParty>(guest, false);
if (attached)
rsvpDate = attached->property("rsvp").toDate();
diff --git a/examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/person.cpp b/examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/person.cpp
new file mode 100644
index 0000000000..fe3d19b58d
--- /dev/null
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/person.cpp
@@ -0,0 +1,87 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+#include "person.h"
+
+Person::Person(QObject *parent) : QObject(parent)
+{
+ m_shoe = new ShoeDescription(this);
+}
+
+int ShoeDescription::size() const
+{
+ return m_size;
+}
+
+void ShoeDescription::setSize(int size)
+{
+ if (m_size != size) {
+ m_size = size;
+ emit shoeChanged();
+ }
+}
+
+QColor ShoeDescription::color() const
+{
+ return m_color;
+}
+
+void ShoeDescription::setColor(const QColor &color)
+{
+ if (m_color != color) {
+ m_color = color;
+ emit shoeChanged();
+ }
+}
+
+QString ShoeDescription::brand() const
+{
+ return m_brand;
+}
+
+void ShoeDescription::setBrand(const QString &brand)
+{
+ if (m_brand != brand) {
+ m_brand = brand;
+ emit shoeChanged();
+ }
+}
+
+qreal ShoeDescription::price() const
+{
+ return m_price;
+}
+
+void ShoeDescription::setPrice(qreal price)
+{
+ if (m_price != price) {
+ m_price = price;
+ emit shoeChanged();
+ }
+}
+
+QString Person::name() const
+{
+ return m_name;
+}
+
+void Person::setName(const QString &name)
+{
+ if (m_name != name) {
+ m_name = name;
+ emit nameChanged();
+ }
+}
+
+ShoeDescription *Person::shoe() const
+{
+ return m_shoe;
+}
+
+void Person::setShoe(ShoeDescription *shoe)
+{
+ if (m_shoe != shoe) {
+ m_shoe = shoe;
+ emit shoeChanged();
+ }
+}
diff --git a/examples/qml/referenceexamples/grouped/person.h b/examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/person.h
index b5fa469025..0ed76223ba 100644
--- a/examples/qml/referenceexamples/grouped/person.h
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/person.h
@@ -1,20 +1,20 @@
-// Copyright (C) 2021 The Qt Company Ltd.
+// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#ifndef PERSON_H
#define PERSON_H
+#include <QtQml/qqml.h>
#include <QObject>
#include <QColor>
-#include <QtQml/qqml.h>
class ShoeDescription : public QObject
{
Q_OBJECT
- Q_PROPERTY(int size READ size WRITE setSize)
- Q_PROPERTY(QColor color READ color WRITE setColor)
- Q_PROPERTY(QString brand READ brand WRITE setBrand)
- Q_PROPERTY(qreal price READ price WRITE setPrice)
+ Q_PROPERTY(int size READ size WRITE setSize NOTIFY shoeChanged FINAL)
+ Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY shoeChanged FINAL)
+ Q_PROPERTY(QString brand READ brand WRITE setBrand NOTIFY shoeChanged FINAL)
+ Q_PROPERTY(qreal price READ price WRITE setPrice NOTIFY shoeChanged FINAL)
QML_ANONYMOUS
public:
using QObject::QObject;
@@ -31,6 +31,9 @@ public:
qreal price() const;
void setPrice(qreal);
+signals:
+ void shoeChanged();
+
private:
int m_size = 0;
QColor m_color;
@@ -41,21 +44,28 @@ private:
class Person : public QObject
{
Q_OBJECT
- Q_PROPERTY(QString name READ name WRITE setName)
-// ![1]
- Q_PROPERTY(ShoeDescription *shoe READ shoe)
-// ![1]
- QML_ANONYMOUS
+ Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged FINAL)
+ Q_PROPERTY(ShoeDescription *shoe READ shoe WRITE setShoe NOTIFY shoeChanged FINAL)
+ QML_ELEMENT
+ QML_UNCREATABLE("Person is an abstract base class.")
public:
using QObject::QObject;
+ Person(QObject *parent = nullptr);
+
QString name() const;
void setName(const QString &);
- ShoeDescription *shoe();
+ ShoeDescription *shoe() const;
+ void setShoe(ShoeDescription *shoe);
+
+signals:
+ void nameChanged();
+ void shoeChanged();
+
private:
QString m_name;
- ShoeDescription m_shoe;
+ ShoeDescription *m_shoe = nullptr;
};
class Boy : public Person
diff --git a/examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/qmldir.in b/examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/qmldir.in
new file mode 100644
index 0000000000..5289a31938
--- /dev/null
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/qmldir.in
@@ -0,0 +1,5 @@
+module People
+typeinfo foreign.qmltypes
+prefer :/qt/qml/People/
+Main 254.0 Main.qml
+depends QtQuick
diff --git a/examples/qml/tutorials/extending-qml-advanced/extending-qml-advanced.pro b/examples/qml/tutorials/extending-qml-advanced/extending-qml-advanced.pro
new file mode 100644
index 0000000000..387d880a7d
--- /dev/null
+++ b/examples/qml/tutorials/extending-qml-advanced/extending-qml-advanced.pro
@@ -0,0 +1,10 @@
+TEMPLATE = subdirs
+
+SUBDIRS += \
+ advanced1-Base-project \
+ advanced2-Inheritance-and-coercion \
+ advanced3-Default-properties \
+ advanced4-Grouped-properties
+ advanced5-Attached-properties \
+ advanced6-Property-value-source \
+ advanced7-Extension-objects \
diff --git a/src/qml/doc/images/extending-qml-advanced-word-cloud.png b/src/qml/doc/images/extending-qml-advanced-word-cloud.png
new file mode 100644
index 0000000000..b479b4f793
--- /dev/null
+++ b/src/qml/doc/images/extending-qml-advanced-word-cloud.png
Binary files differ
diff --git a/src/qml/doc/src/cppintegration/definetypes.qdoc b/src/qml/doc/src/cppintegration/definetypes.qdoc
index 6dcb76eb99..61dfd34e3f 100644
--- a/src/qml/doc/src/cppintegration/definetypes.qdoc
+++ b/src/qml/doc/src/cppintegration/definetypes.qdoc
@@ -390,7 +390,11 @@ type definition allows the programmer to supply an additional type, known as the
\e{extension type}, when registering the class. Its members are transparently
merged with the original target class when used from within QML. For example:
-\snippet referenceexamples/extended/example.qml 0
+\qml
+QLineEdit {
+ leftMargin: 20
+}
+\endqml
The \c leftMargin property is a new property added to an existing C++ type, \l
QLineEdit, without modifying its source code.
@@ -409,9 +413,6 @@ extended property is accessed. The extension class is created and the target
object is passed in as the parent. When the property on the original is
accessed, the corresponding property on the extension object is used instead.
-The \l{Extending QML - Extension Objects Example}{Extension Objects Example}
-demonstrates a usage of extension objects.
-
\section2 Registering Foreign Types
There may be C++ types that cannot be modified to hold the above mentioned
diff --git a/src/qml/doc/src/cppintegration/extending-tutorial-advanced.qdoc b/src/qml/doc/src/cppintegration/extending-tutorial-advanced.qdoc
new file mode 100644
index 0000000000..ba57722dd2
--- /dev/null
+++ b/src/qml/doc/src/cppintegration/extending-tutorial-advanced.qdoc
@@ -0,0 +1,380 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
+
+/*!
+\example tutorials/extending-qml-advanced
+\meta tags{qml,extensions,advanced}
+
+\title Writing advanced QML Extensions with C++
+\brief Tutorial about advanced extensions to QML with Qt C++.
+
+
+\section1 BirthdayParty Base Project
+\c extending-qml-advanced/advanced1-Base-project
+
+This tutorial uses the example of a birthday party to demonstrate some of
+the features of QML. The code for the various features explained below is
+based on this birthday party project and relies on some of the material in the
+first tutorial on \l {Writing QML Extensions with C++}{QML extensions}. This
+simple example is then expanded upon to illustrate the various QML extensions
+explained below. The complete code for each new extension to the code can be
+found in the tutorials at the location specified under each section's title or
+by following the link to the code at the very end of this page.
+
+\image extending-qml-advanced-word-cloud.png
+
+The base project defines the \c Person class and the \c BirthdayParty class,
+which model the attendees and the party itself respectively.
+\quotefromfile tutorials/extending-qml-advanced/advanced1-Base-project/person.h
+ \skipto class
+ \printuntil QML_ELEMENT
+ \dots
+ \skipuntil private:
+ \printuntil /\};/
+
+\quotefromfile tutorials/extending-qml-advanced/advanced1-Base-project/birthdayparty.h
+ \skipto class
+ \printuntil QML_ELEMENT
+ \dots
+ \skipto Person *m_host = nullptr;
+ \printuntil /\};/
+
+All the information about the party can then be stored in the corresponding QML
+file.
+\quotefromfile tutorials/extending-qml-advanced/advanced1-Base-project/Main.qml
+ \skipto BirthdayParty
+ \printuntil /^\}/
+
+The \c main.cpp file creates a simple shell application that displays whose
+birthday it is and who is invited to their party.
+\quotefromfile tutorials/extending-qml-advanced/advanced1-Base-project/main.cpp
+ \skipto engine
+ \printuntil }
+
+The app outputs the following summary of the party.
+\badcode
+"Bob Jones" is having a birthday!
+They are inviting:
+ "Leo Hodges"
+ "Jack Smith"
+ "Anne Brown"
+\endcode
+
+The following sections go into how to add support for \c Boy and \c Girl
+attendees instead of just \c Person by using inheritance and coercion, how to
+make use of default properties to implicitly assign attendees of the party as
+guests, how to assign properties as groups instead of one by one, how to use
+attached objects to keep track of invited guests' reponses, how to use a
+property value source to display the lyrics of the happy birthday song over
+time, and how to expose third party objects to QML.
+
+
+
+\section1 Inheritance and Coercion
+\c extending-qml-advanced/advanced2-Inheritanace-and-coercion
+
+Right now, each attendant is being modelled as a person. This is a bit too
+generic and it would be nice to be able to know more about the attendees. By
+specializing them as boys and girls, we can already get a better idea of who's
+coming.
+
+To do this, the \c Boy and \c Girl classes are introduced, both inheriting from
+\c Person.
+\quotefromfile tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion/person.h
+ \skipto Boy
+ \printuntil /^\};/
+
+\quotefromfile tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion/person.h
+ \skipto Girl
+ \printuntil /^\};/
+
+The \c Person class remains unaltered and the \c Boy and \c Girl C++ classes
+are trivial extensions of it. The types and their QML name are registered with
+the QML engine with \l QML_ELEMENT.
+
+Notice that the \c host and \c guests properties in \c BirthdayParty still take
+instances of \c Person.
+\quotefromfile tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion/birthdayparty.h
+ \skipto BirthdayParty
+ \printuntil QML_ELEMENT
+ \dots
+ \skipto /^\};/
+ \printuntil /^\};/
+
+The implementation of the \c Person class itself has not been changed. However,
+as the \c Person class was repurposed as a common base for \c Boy and \c Girl,
+\c Person should no longer be instantiable from QML directly. An explicit
+\c Boy or \c Girl should be instantiated instead.
+\quotefromfile tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion/person.h
+ \skipto Person
+ \printto Q_OBJECT
+ \dots
+ \skipto QML_ELEMENT
+ \printuntil QML_UNCREATABLE
+ \dots
+ \skipto /^\};/
+ \printuntil /^\};/
+
+While we want to disallow instantiating \c Person from within QML, it still
+needs to be registered with the QML engine so that it can be used as a property
+type and other types can be coerced to it. This is what the QML_UNCREATABLE
+macro does. As all three types, \c Person, \c Boy and \c Girl, have been
+registered with the QML system, on assignment, QML automatically (and type-safely)
+converts the \c Boy and \c Girl objects into a \c Person.
+
+With these changes in place, we can now specify the birthday party with the
+extra information about the attendees as follows.
+\quotefromfile tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion/Main.qml
+ \skipto BirthdayParty
+ \printuntil /^\}/
+
+
+
+\section1 Default Properties
+\c extending-qml-advanced/advanced3-Default-properties
+
+Currently, in the QML file, each property is assigned explicitly. For example,
+the \c host property is assigned a \c Boy and the \c guests property is
+assigned a list of \c Boy or \c Girl. This is easy but it can be made a bit
+simpler for this specific use case. Instead of assigning the \c guests property
+explicitly, we can add \c Boy and \c Girl objects inside the party directly
+and have them assigned to \c guests implicitly. It makes sense that all the
+attendees that we specify, and that are not the host, are guests. This change
+is purely syntactical but it can add a more natural feel in many situations.
+
+The \c guests property can be designated as the default property of
+\c BirthdayParty. Meaning that each object created inside of a \c BirthdayParty
+is implicitly appended to the default property \c guests. The resulting QML
+looks like this.
+\quotefromfile tutorials/extending-qml-advanced/advanced3-Default-properties/Main.qml
+ \skipto BirthdayParty
+ \printuntil /^\}/
+
+The only change required to enable this behavior is to add the \c DefaultProperty
+class info annotation to \c BirthdayParty to designate \c guests as its default
+property.
+\quotefromfile tutorials/extending-qml-advanced/advanced3-Default-properties/birthdayparty.h
+ \skipto class
+ \printuntil QML_ELEMENT
+ \dots
+ \skipto /^\};/
+ \printuntil /^\};/
+
+You may already be familiar with this mechanism. The default property for all
+descendants of \c Item in QML is the \c data property. All elements not
+explicitly added to a property of an \c Item will be added to \c data. This
+makes the structure clear and reduces unnecessary noise in the code.
+
+\sa {Specifying Default and Parent Properties for QML Object Types}
+
+
+
+\section1 Grouped Properties
+\c extending-qml-advanced/advanced4-Grouped-properties
+
+More information is needed about the shoes of the guests. Aside from their
+size, we also want to store the shoes' color, brand, and price. This
+information is stored in a \c ShoeDescription class.
+\quotefromfile tutorials/extending-qml-advanced/advanced4-Grouped-properties/person.h
+ \skipto ShoeDescription
+ \printuntil price
+ \dots
+ \skipto /^\};/
+ \printuntil /^\};/
+
+Each person now has two properties, a \c name and a shoe description \c shoe.
+\quotefromfile tutorials/extending-qml-advanced/advanced4-Grouped-properties/person.h
+ \skipto Person
+ \printuntil shoe
+ \dots
+ \skipto /^\};/
+ \printuntil /^\};/
+
+Specifying the values for each element of the shoe description works but is a
+bit repetitive.
+\quotefromfile tutorials/extending-qml-advanced/advanced4-Grouped-properties/Main.qml
+ \skipto Girl
+ \printuntil }
+
+Grouped properties provide a more elegant way of assigning these properties.
+Instead of assigning the values to each property one-by-one, the individual
+values can be passed as a group to the \c shoe property making the code more
+readable. No changes are required to enable this feature as it is available by
+default for all of QML.
+\quotefromfile tutorials/extending-qml-advanced/advanced4-Grouped-properties/Main.qml
+ \skipto host
+ \printuntil /^....}/
+
+\sa {Grouped Properties}
+
+
+
+\section1 Attached Properties
+\c extending-qml-advanced/advanced5-Attached-properties
+
+The time has come for the host to send out invitations. To keep track of which
+guests have responded to the invitation and when, we need somewhere to store
+that information. Storing it in the \c BirthdayParty object iself would not
+really fit. A better way would be to store the responses as attached objects to
+the party object.
+
+First, we declare the \c BirthdayPartyAttached class which holds the guest reponses.
+\quotefromfile tutorials/extending-qml-advanced/advanced5-Attached-properties/birthdayparty.h
+ \skipto BirthdayPartyAttached
+ \printuntil QML_ANONYMOUS
+ \dots
+ \skipto /^\};/
+ \printuntil /^\};/
+
+And we attach it to the \c BirthdayParty class and define
+\c qmlAttachedProperties() to return the attached object.
+\quotefromfile tutorials/extending-qml-advanced/advanced5-Attached-properties/birthdayparty.h
+ \skipto /BirthdayParty : public QObject/
+ \printuntil /^{/
+ \dots
+ \skipto QML_ATTACHED
+ \printuntil QML_ATTACHED
+ \dots
+ \skipto qmlAttachedProperties
+ \printuntil qmlAttachedProperties
+ \skipto /^\};/
+ \printuntil /^\};/
+
+Now, attached objects can be used in the QML to hold the rsvp information of the invited guests.
+\quotefromfile tutorials/extending-qml-advanced/advanced5-Attached-properties/Main.qml
+ \skipto BirthdayParty
+ \printuntil /^}/
+
+Finally, the information can be accessed in the following way.
+\quotefromfile tutorials/extending-qml-advanced/advanced5-Attached-properties/main.cpp
+ \skipto rsvpDate
+ \printuntil attached->property("rsvp").toDate();
+
+The program outputs the following summary of the party to come.
+\badcode
+"Jack Smith" is having a birthday!
+He is inviting:
+ "Robert Campbell" RSVP date: "Wed Mar 1 2023"
+ "Leo Hodges" RSVP date: "Mon Mar 6 2023"
+\endcode
+
+\sa {Providing Attached Properties}
+
+
+
+\section1 Property Value Source
+\c extending-qml-advanced/advanced6-Property-value-source
+
+During the party the guests have to sing for the host. It would be handy if the
+program could display the lyrics customized for the occasion to help the
+guests. To this end, a property value source is used to generate the verses of
+the song over time.
+\quotefromfile tutorials/extending-qml-advanced/advanced6-Property-value-source/happybirthdaysong.h
+ \skipto class
+ \printuntil Q_INTERFACES
+ \dots
+ \skipto setTarget
+ \printuntil setTarget
+ \skipto /^\};/
+ \printuntil /^\};/
+
+The class \c HappyBirthdaySong is added as a value source. It must inherit from
+\c QQmlPropertyValueSource and implement the QQmlPropertyValueSource interface
+with the Q_INTERFACES macro. The \c setTarget() function is used to define
+which property this source acts upon. In this case, the value source writes to
+the \c announcement property of the \c BirthdayParty to display the lyrics
+over time. It has an internal timer that causes the \c announcement
+property of the party to be set to the next line of the lyrics repeatedly.
+
+In QML, a \c HappyBirthdaySong is instantiated inside the \c BirthdayParty. The
+\c on keyword in its signature is used to specify the property that the value
+source targets, in this case \c announcement. The \c name property of the
+\c HappyBirthdaySong object is also \l {Property Binding}{bound} to the name of
+the host of the party.
+\quotefromfile tutorials/extending-qml-advanced/advanced6-Property-value-source/Main.qml
+ \skipto BirthdayParty
+ \printuntil }
+ \dots
+ \skipto /^\}/
+ \printuntil /^\}/
+
+The program displays the time at which the party started using the
+\c partyStarted signal and then prints the following happy birthday verses
+over and over.
+\badcode
+Happy birthday to you,
+Happy birthday to you,
+Happy birthday dear Bob Jones,
+Happy birthday to you!
+\endcode
+
+\sa {Property Value Sources}
+
+
+
+\section1 Foreign objects integration
+\c extending-qml-advanced/advanced7-Foreign-objects-integration
+
+Instead of just printing the lyrics out to the console, the attendees would
+like to use a more fancy display with support for colors. They would like to
+integrate it in the project but currently it is not possible to configure the
+screen from QML because it comes from a third party library. To solve this, the
+necessary types need to be exposed to the QML engine so its properties are
+available for modification in QML directly.
+
+The display can be controlled by the \c ThirdPartyDisplay class. It has
+properties to define the content and the foreground and background colors of the text
+to display.
+\quotefromfile tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/library/ThirdPartyDisplay.h
+ \skipto ThirdPartyDisplay
+ \printuntil backgroundColor
+ \dots
+ \skipto };
+ \printuntil };
+
+To expose this type to QML, we can register it with the engine with
+QML_ELEMENT. However, since the class isn't accessible for modification,
+QML_ELEMENT cannot simply be added to it. To register the type with the engine,
+the type needs to be registered from the outside. This is what QML_FOREIGN is
+for. When used in a type in conjunction with other QML macros, the other macros
+apply not to the type they reside in but to the foreign type designated by
+QML_FOREIGN.
+\quotefromfile tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/foreigndisplay.h
+ \skipto ForeignDisplay
+ \printuntil };
+
+This way, the BirthdayParty now has a new property with the display.
+\quotefromfile tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/birthdayparty.h
+ \skipuntil BirthdayPartyAttached
+ \skipto BirthdayParty
+ \printto Q_CLASSINFO
+ \dots
+ \skipto };
+ \printuntil };
+
+And, in QML, the colors of the text on the fancy third display can be set explicitly.
+\quotefromfile tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/Main.qml
+ \skipto BirthdayParty
+ \printuntil BirthdayParty
+ \skipto display:
+ \printuntil }
+ \dots
+ \skipto /^}/
+ \printuntil /^}/
+
+Setting the \c announcement property of the BirthdayParty now sends the
+message to the fancy display instead of printing it itself.
+\quotefromfile tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/birthdayparty.cpp
+ \skipto setAnnouncement
+ \printuntil /^}/
+
+The output then looks like this over and over similar to the previous section.
+\badcode
+[Fancy ThirdPartyDisplay] Happy birthday to you,
+[Fancy ThirdPartyDisplay] Happy birthday to you,
+[Fancy ThirdPartyDisplay] Happy birthday dear Bob Jones,
+[Fancy ThirdPartyDisplay] Happy birthday to you!
+\endcode
+
+\sa {Registering Foreign Types}
+*/
diff --git a/src/qml/doc/src/cppintegration/extending-tutorial.qdoc b/src/qml/doc/src/cppintegration/extending-tutorial.qdoc
index 8813309851..fbf03ee8b8 100644
--- a/src/qml/doc/src/cppintegration/extending-tutorial.qdoc
+++ b/src/qml/doc/src/cppintegration/extending-tutorial.qdoc
@@ -202,6 +202,7 @@ disappears, and the application outputs:
\endcode
+
\section1 Chapter 3: Adding Property Bindings
\c extending-qml/chapter3-bindings
@@ -251,6 +252,7 @@ bindings are invoked so often and relied upon in QML usage, users of your
custom QML types may see unexpected behavior if bindings are not implemented.
+
\section1 Chapter 4: Using Custom Property Types
\c extending-qml/chapter4-customPropertyTypes
@@ -339,6 +341,7 @@ Using CMake:
\dots
+
\section1 Chapter 5: Using List Property Types
\c extending-qml/chapter5-listproperties
@@ -382,6 +385,7 @@ properties and to draw the slice according to these values. This is a straightfo
modification if you have read the previous pages in this tutorial, so the code is not shown here.
+
\section1 Chapter 6: Writing an Extension Plugin
\c extending-qml/chapter6-plugins
@@ -456,6 +460,7 @@ The module "Charts" will be loaded by the QML engine, and the types provided by
module will be available for use in any QML document which imports it.
+
\section1 Chapter 7: Summary
In this tutorial, we've shown the basic steps for creating a QML extension:
@@ -493,4 +498,6 @@ Or randomly add and remove slices from time to time using \l{Property Value Sour
}
\endcode
+\note To continue learning about QML extensions and features follow the
+\l {Writing advanced QML Extensions with C++} tutorial.
*/
diff --git a/src/qml/doc/src/examples.qdoc b/src/qml/doc/src/examples.qdoc
deleted file mode 100644
index 4a4fdf0454..0000000000
--- a/src/qml/doc/src/examples.qdoc
+++ /dev/null
@@ -1,47 +0,0 @@
-// Copyright (C) 2017 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
-
-/*!
-\group qmlextendingexamples
-\title Qt QML Examples
-\brief List of Qt QML examples for reference.
-
-The list of examples demonstrating how to extend C++ to QML or the other way
-around.
-
-\noautolist
-
-\table
- \row
- \li \l {Extending QML - Adding Types Example}
- \li Exporting C++ Classes
- \row
- \li \l {Extending QML - Object and List Property Types Example}
- \li Exporting C++ Properties
- \row
- \li \l {Extending QML - Extension Objects Example}
- \li Extension Objects
- \row
- \li \l {Extending QML - Inheritance and Coercion Example}
- \li C++ Inheritance and Coercion
- \row
- \li \l {Extending QML - Methods Example}
- \li Methods Support
- \row
- \li \l {Extending QML - Attached Properties Example}
- \li Attached Properties
- \row
- \li \l {Extending QML - Signal Support Example}
- \li Signal Support
- \row
- \li \l {Extending QML - Property Value Source Example}
- \li Property Value Source
- \row
- \li \l {Extending QML - Default Property Example}
- \li Default Property
- \row
- \li \l {Extending QML - Grouped Properties Example}
- \li Grouped Properties
-\endtable
-
-*/
diff --git a/src/qml/doc/src/qmlfunctions.qdoc b/src/qml/doc/src/qmlfunctions.qdoc
index 540c64dc4c..b9e32afd9c 100644
--- a/src/qml/doc/src/qmlfunctions.qdoc
+++ b/src/qml/doc/src/qmlfunctions.qdoc
@@ -458,7 +458,7 @@
\b{NOTE:} You may want to use \l QML_NAMED_ELEMENT() instead of \l QML_ELEMENT due to the fact that
the element will be named like the struct it is contained in, not the foreign type.
- See \l {Extending QML - Extension Objects Example} for an example.
+ See the \l {Extension Objects} for an example.
\sa QML_ELEMENT, QML_NAMED_ELEMENT(), QML_FOREIGN_NAMESPACE()
*/
diff --git a/src/qml/doc/src/qtqml.qdoc b/src/qml/doc/src/qtqml.qdoc
index 2da6a8c9e0..8f44fa87c1 100644
--- a/src/qml/doc/src/qtqml.qdoc
+++ b/src/qml/doc/src/qtqml.qdoc
@@ -115,10 +115,11 @@ the QML code to interact with C++ code.
\li \l {Important C++ Classes Provided By The Qt QML Module}
\endlist
-\section2 Examples
+\section2 Tutorials
\list
\li \l {Writing QML Extensions with C++}
+ \li \l {Writing advanced QML Extensions with C++}
\endlist
\omit
@@ -165,6 +166,5 @@ Further information for writing QML applications:
\list
\li \l {Qt QML C++ Classes} {C++ Classes}
\li \l {Qt QML QML Types} {QML Types}
- \li \l {Qt QML Examples} {Examples}
\endlist
*/
diff --git a/src/qml/qml/qqmllist.cpp b/src/qml/qml/qqmllist.cpp
index 5fd077c7c1..a166041070 100644
--- a/src/qml/qml/qqmllist.cpp
+++ b/src/qml/qml/qqmllist.cpp
@@ -447,7 +447,7 @@ Q_PROPERTY(QQmlListProperty<Fruit> fruit READ fruit)
QML list properties are type-safe - in this case \c {Fruit} is a QObject type that
\c {Apple}, \c {Orange} and \c {Banana} all derive from.
-\sa {Extending QML - Object and List Property Types Example}
+\sa {Chapter 5: Using List Property Types}
*/
/*!
diff --git a/src/quick/doc/src/examples.qdoc b/src/quick/doc/src/examples.qdoc
index eb4ff4591d..8fe736da54 100644
--- a/src/quick/doc/src/examples.qdoc
+++ b/src/quick/doc/src/examples.qdoc
@@ -81,11 +81,12 @@ steps such as use cases and introductory material. For more information about Qt
\section2 Extending QML
-The following tutorials show how a QML-based application can be combined with
-C++ code using the \l{Qt QML} module. For information about extending QML, visit
-the \l{Writing QML Extensions with C++} page.
-
-\annotatedlist{qmlextendingexamples}
+The following tutorials show how a QML-based application can be combined and
+exteneded with C++ code using the \l{Qt QML} module.
+\list
+ \li \l {Writing QML Extensions with C++}
+ \li \l {Writing advanced QML Extensions with C++}
+\endlist
\section1 Examples
diff --git a/tests/auto/guiapplauncher/examples.txt b/tests/auto/guiapplauncher/examples.txt
index 40c41e59fb..03ad71e7e2 100644
--- a/tests/auto/guiapplauncher/examples.txt
+++ b/tests/auto/guiapplauncher/examples.txt
@@ -36,17 +36,6 @@
"quick/quickwidgets/qquickviewcomparison Example", "examples/quick/quickwidgets/qquickviewcomparison", "qquickviewcomparison", 0, -1
"quick/quickwidgets/quickwidget Example", "examples/quick/quickwidgets/quickwidget", "quickwidget", 0, -1
"qml/shell Example", "examples/qml/shell", "shell", 10, -1
-"qml/referenceexamples/extended Example", "examples/qml/referenceexamples/extended", "extended", 0, -1
-"qml/referenceexamples/binding Example", "examples/qml/referenceexamples/binding", "binding", 10, -1
-"qml/referenceexamples/adding Example", "examples/qml/referenceexamples/adding", "adding", 10, -1
-"qml/referenceexamples/attached Example", "examples/qml/referenceexamples/attached", "attached", 10, -1
-"qml/referenceexamples/default Example", "examples/qml/referenceexamples/default", "default", 10, -1
-"qml/referenceexamples/signal Example", "examples/qml/referenceexamples/signal", "signal", 10, -1
-"qml/referenceexamples/coercion Example", "examples/qml/referenceexamples/coercion", "coercion", 10, -1
-"qml/referenceexamples/grouped Example", "examples/qml/referenceexamples/grouped", "grouped", 10, -1
-"qml/referenceexamples/valuesource Example", "examples/qml/referenceexamples/valuesource", "valuesource", 10, -1
-"qml/referenceexamples/properties Example", "examples/qml/referenceexamples/properties", "properties", 10, -1
-"qml/referenceexamples/methods Example", "examples/qml/referenceexamples/methods", "methods", 10, -1
"qml/networkaccessmanagerfactory Example", "examples/qml/networkaccessmanagerfactory", "networkaccessmanagerfactory", 10, -1
"qml/xmlhttprequest Example", "examples/qml/xmlhttprequest", "xmlhttprequest", 0, -1
"qmltest/qmltest Example", "examples/qmltest/qmltest", "tst_qmltestexample", 10, -1