aboutsummaryrefslogtreecommitdiffstats
path: root/examples/qml
diff options
context:
space:
mode:
Diffstat (limited to 'examples/qml')
-rw-r--r--examples/qml/CMakeLists.txt15
-rw-r--r--examples/qml/doc/src/qml-extending.qdoc339
-rw-r--r--examples/qml/dynamicscene/CMakeLists.txt52
-rw-r--r--examples/qml/dynamicscene/GenericSceneItem.qml12
-rw-r--r--examples/qml/dynamicscene/PaletteItem.qml22
-rw-r--r--examples/qml/dynamicscene/PerspectiveItem.qml27
-rw-r--r--examples/qml/dynamicscene/Sun.qml36
-rw-r--r--examples/qml/dynamicscene/doc/images/qml-dynamicscene-example.pngbin32286 -> 0 bytes
-rw-r--r--examples/qml/dynamicscene/doc/src/dynamicscene.qdoc10
-rw-r--r--examples/qml/dynamicscene/dynamicscene.pro9
-rw-r--r--examples/qml/dynamicscene/dynamicscene.qml237
-rw-r--r--examples/qml/dynamicscene/dynamicscene.qmlproject16
-rw-r--r--examples/qml/dynamicscene/dynamicscene.qrc18
-rw-r--r--examples/qml/dynamicscene/images/NOTE1
-rw-r--r--examples/qml/dynamicscene/images/face-smile.pngbin15408 -> 0 bytes
-rw-r--r--examples/qml/dynamicscene/images/moon.pngbin1757 -> 0 bytes
-rw-r--r--examples/qml/dynamicscene/images/rabbit_brown.pngbin1245 -> 0 bytes
-rw-r--r--examples/qml/dynamicscene/images/rabbit_bw.pngbin1759 -> 0 bytes
-rw-r--r--examples/qml/dynamicscene/images/star.pngbin259 -> 0 bytes
-rw-r--r--examples/qml/dynamicscene/images/sun.pngbin8110 -> 0 bytes
-rw-r--r--examples/qml/dynamicscene/images/tree_s.pngbin3406 -> 0 bytes
-rw-r--r--examples/qml/dynamicscene/itemCreation.js62
-rw-r--r--examples/qml/dynamicscene/main.cpp4
-rw-r--r--examples/qml/locale/locale.qml101
-rw-r--r--examples/qml/networkaccessmanagerfactory/CMakeLists.txt44
-rw-r--r--examples/qml/networkaccessmanagerfactory/doc/src/networkaccessmanagerfactory.qdoc15
-rw-r--r--examples/qml/networkaccessmanagerfactory/main.cpp97
-rw-r--r--examples/qml/networkaccessmanagerfactory/networkaccessmanagerfactory.pro8
-rw-r--r--examples/qml/networkaccessmanagerfactory/networkaccessmanagerfactory.qmlproject14
-rw-r--r--examples/qml/networkaccessmanagerfactory/networkaccessmanagerfactory.qrc5
-rw-r--r--examples/qml/networkaccessmanagerfactory/view.qml10
-rw-r--r--examples/qml/qml-i18n/CMakeLists.txt51
-rw-r--r--examples/qml/qml-i18n/Main.qml (renamed from examples/qml/qml-i18n/qml-i18n.qml)0
-rw-r--r--examples/qml/qml-i18n/doc/src/i18n.qdoc5
-rw-r--r--examples/qml/qml-i18n/i18n/base.ts4
-rw-r--r--examples/qml/qml-i18n/i18n/qml_en_AU.ts4
-rw-r--r--examples/qml/qml-i18n/i18n/qml_fr.ts4
-rw-r--r--examples/qml/qml-i18n/main.cpp14
-rw-r--r--examples/qml/qml-i18n/qml-i18n.pro1
-rw-r--r--examples/qml/qml-i18n/qml-i18n.qrc5
-rw-r--r--examples/qml/qml-i18n/qmldir5
-rw-r--r--examples/qml/qml.pro17
-rw-r--r--examples/qml/qmldom/CMakeLists.txt37
-rw-r--r--examples/qml/qmldom/qmldomloadeditwrite.cpp500
-rw-r--r--examples/qml/qmlextensionplugins/CMakeLists.txt61
-rw-r--r--examples/qml/qmlextensionplugins/doc/images/qml-plugins-example.pngbin15773 -> 0 bytes
-rw-r--r--examples/qml/qmlextensionplugins/doc/src/qmlpluginex.qdoc43
-rw-r--r--examples/qml/qmlextensionplugins/imports/TimeExample/Clock.qml51
-rw-r--r--examples/qml/qmlextensionplugins/imports/TimeExample/center.pngbin765 -> 0 bytes
-rw-r--r--examples/qml/qmlextensionplugins/imports/TimeExample/clock.pngbin20653 -> 0 bytes
-rw-r--r--examples/qml/qmlextensionplugins/imports/TimeExample/hour.pngbin518 -> 0 bytes
-rw-r--r--examples/qml/qmlextensionplugins/imports/TimeExample/minute.pngbin528 -> 0 bytes
-rw-r--r--examples/qml/qmlextensionplugins/imports/TimeExample/qmldir3
-rw-r--r--examples/qml/qmlextensionplugins/plugin.cpp15
-rw-r--r--examples/qml/qmlextensionplugins/plugins.qml16
-rw-r--r--examples/qml/qmlextensionplugins/plugins.qmlproject18
-rw-r--r--examples/qml/qmlextensionplugins/qmlextensionplugins.pro46
-rw-r--r--examples/qml/qmlextensionplugins/timemodel.cpp51
-rw-r--r--examples/qml/qmlextensionplugins/timemodel.h64
-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/adding/person.h32
-rw-r--r--examples/qml/referenceexamples/attached/CMakeLists.txt44
-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/attached/person.h75
-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/CMakeLists.txt43
-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/CMakeLists.txt43
-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/CMakeLists.txt44
-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/grouped/person.h77
-rw-r--r--examples/qml/referenceexamples/methods/CMakeLists.txt43
-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/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/person.h75
-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/CMakeLists.txt45
-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/shell/CMakeLists.txt47
-rw-r--r--examples/qml/shell/main.cpp116
-rw-r--r--examples/qml/shell/shell.pro9
-rw-r--r--examples/qml/tutorials/CMakeLists.txt4
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/CMakeLists.txt12
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced1-Base-project/CMakeLists.txt50
-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/properties/person.h)12
-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.txt50
-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.txt50
-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.txt49
-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.cpp96
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced4-Grouped-properties/person.h (renamed from examples/qml/referenceexamples/binding/person.h)42
-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.txt49
-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.cpp96
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties/person.h98
-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.txt50
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/Main.qml (renamed from examples/qml/referenceexamples/binding/example.qml)23
-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/valuesource/happybirthdaysong.cpp)16
-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.cpp96
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/person.h98
-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.txt63
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/Main.qml (renamed from examples/qml/referenceexamples/valuesource/example.qml)23
-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/binding/happybirthdaysong.cpp)22
-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.cpp96
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/person.h98
-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--examples/qml/tutorials/extending-qml/CMakeLists.txt2
-rw-r--r--examples/qml/tutorials/extending-qml/chapter1-basics/App.qml (renamed from examples/qml/tutorials/extending-qml/chapter1-basics/app.qml)0
-rw-r--r--examples/qml/tutorials/extending-qml/chapter1-basics/CMakeLists.txt38
-rw-r--r--examples/qml/tutorials/extending-qml/chapter1-basics/chapter1-basics.qrc5
-rw-r--r--examples/qml/tutorials/extending-qml/chapter1-basics/main.cpp2
-rw-r--r--examples/qml/tutorials/extending-qml/chapter1-basics/qmldir6
-rw-r--r--examples/qml/tutorials/extending-qml/chapter2-methods/App.qml (renamed from examples/qml/tutorials/extending-qml/chapter2-methods/app.qml)0
-rw-r--r--examples/qml/tutorials/extending-qml/chapter2-methods/CMakeLists.txt38
-rw-r--r--examples/qml/tutorials/extending-qml/chapter2-methods/chapter2-methods.qrc5
-rw-r--r--examples/qml/tutorials/extending-qml/chapter2-methods/main.cpp2
-rw-r--r--examples/qml/tutorials/extending-qml/chapter2-methods/qmldir6
-rw-r--r--examples/qml/tutorials/extending-qml/chapter3-bindings/App.qml (renamed from examples/qml/tutorials/extending-qml/chapter3-bindings/app.qml)0
-rw-r--r--examples/qml/tutorials/extending-qml/chapter3-bindings/CMakeLists.txt38
-rw-r--r--examples/qml/tutorials/extending-qml/chapter3-bindings/chapter3-bindings.qrc5
-rw-r--r--examples/qml/tutorials/extending-qml/chapter3-bindings/main.cpp2
-rw-r--r--examples/qml/tutorials/extending-qml/chapter3-bindings/qmldir6
-rw-r--r--examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/App.qml (renamed from examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/app.qml)0
-rw-r--r--examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/CMakeLists.txt37
-rw-r--r--examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/chapter4-customPropertyTypes.qrc5
-rw-r--r--examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/main.cpp2
-rw-r--r--examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/qmldir6
-rw-r--r--examples/qml/tutorials/extending-qml/chapter5-listproperties/App.qml (renamed from examples/qml/tutorials/extending-qml/chapter5-listproperties/app.qml)0
-rw-r--r--examples/qml/tutorials/extending-qml/chapter5-listproperties/CMakeLists.txt38
-rw-r--r--examples/qml/tutorials/extending-qml/chapter5-listproperties/chapter5-listproperties.qrc5
-rw-r--r--examples/qml/tutorials/extending-qml/chapter5-listproperties/main.cpp2
-rw-r--r--examples/qml/tutorials/extending-qml/chapter5-listproperties/qmldir6
-rw-r--r--examples/qml/tutorials/extending-qml/chapter6-plugins/App.qml (renamed from examples/qml/tutorials/extending-qml/chapter6-plugins/app.qml)0
-rw-r--r--examples/qml/tutorials/extending-qml/chapter6-plugins/CMakeLists.txt37
-rw-r--r--examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/CMakeLists.txt42
-rw-r--r--examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/qmldir5
-rw-r--r--examples/qml/tutorials/extending-qml/chapter6-plugins/app.qrc5
-rw-r--r--examples/qml/tutorials/extending-qml/chapter6-plugins/main.cpp4
-rw-r--r--examples/qml/tutorials/extending-qml/chapter6-plugins/qmldir3
-rw-r--r--examples/qml/xmlhttprequest/CMakeLists.txt44
-rw-r--r--examples/qml/xmlhttprequest/data.xml5
-rw-r--r--examples/qml/xmlhttprequest/doc/images/qml-xmlhttprequest-example.pngbin20934 -> 0 bytes
-rw-r--r--examples/qml/xmlhttprequest/doc/src/xmlhttprequest.qdoc20
-rw-r--r--examples/qml/xmlhttprequest/main.cpp26
-rw-r--r--examples/qml/xmlhttprequest/methods.js34
-rw-r--r--examples/qml/xmlhttprequest/xmlhttprequest.pro15
-rw-r--r--examples/qml/xmlhttprequest/xmlhttprequest.qml28
-rw-r--r--examples/qml/xmlhttprequest/xmlhttprequest.qmlproject16
-rw-r--r--examples/qml/xmlhttprequest/xmlhttprequest.qrc7
259 files changed, 2931 insertions, 5371 deletions
diff --git a/examples/qml/CMakeLists.txt b/examples/qml/CMakeLists.txt
index 7bc4cb2625..e5dc00d0fd 100644
--- a/examples/qml/CMakeLists.txt
+++ b/examples/qml/CMakeLists.txt
@@ -1,17 +1,10 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-add_subdirectory(referenceexamples)
add_subdirectory(tutorials)
-qt_internal_add_example(shell)
-if(TARGET Qt::Quick)
- qt_internal_add_example(qmlextensionplugins)
- qt_internal_add_example(xmlhttprequest)
- if (TARGET Qt::lupdate)
+if(TARGET Qt6::Quick)
+ if (TARGET Qt6::lupdate)
qt_internal_add_example(qml-i18n)
endif()
- qt_internal_add_example(dynamicscene)
-endif()
-if(QT_FEATURE_qml_network AND TARGET Qt::Quick)
- qt_internal_add_example(networkaccessmanagerfactory)
endif()
+
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/dynamicscene/CMakeLists.txt b/examples/qml/dynamicscene/CMakeLists.txt
deleted file mode 100644
index b91ed5aca7..0000000000
--- a/examples/qml/dynamicscene/CMakeLists.txt
+++ /dev/null
@@ -1,52 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(dynamicscene LANGUAGES CXX)
-
-set(CMAKE_INCLUDE_CURRENT_DIR ON)
-set(CMAKE_AUTOMOC ON)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/qml/dynamicscene")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Gui Qml Quick)
-
-qt_add_executable(dynamicsceneexample WIN32 MACOSX_BUNDLE main.cpp)
-
-target_link_libraries(dynamicsceneexample PUBLIC
- Qt::Core
- Qt::Gui
- Qt::Qml
- Qt::Quick
-)
-
-qt_add_qml_module(dynamicsceneexample
- URI dynamicscene
- AUTO_RESOURCE_PREFIX
- QML_FILES
- "GenericSceneItem.qml"
- "PaletteItem.qml"
- "PerspectiveItem.qml"
- "Sun.qml"
- "dynamicscene.qml"
- "itemCreation.js"
- RESOURCES
- "images/NOTE"
- "images/face-smile.png"
- "images/moon.png"
- "images/rabbit_brown.png"
- "images/rabbit_bw.png"
- "images/star.png"
- "images/sun.png"
- "images/tree_s.png"
-)
-
-install(TARGETS dynamicsceneexample
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/qml/dynamicscene/GenericSceneItem.qml b/examples/qml/dynamicscene/GenericSceneItem.qml
deleted file mode 100644
index 5ff3760bb7..0000000000
--- a/examples/qml/dynamicscene/GenericSceneItem.qml
+++ /dev/null
@@ -1,12 +0,0 @@
-// Copyright (C) 2021 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-import QtQuick
-
-Image {
- property bool created: false
- property string image
-
- source: image
-
-}
diff --git a/examples/qml/dynamicscene/PaletteItem.qml b/examples/qml/dynamicscene/PaletteItem.qml
deleted file mode 100644
index ef03b8ce38..0000000000
--- a/examples/qml/dynamicscene/PaletteItem.qml
+++ /dev/null
@@ -1,22 +0,0 @@
-// Copyright (C) 2021 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-import QtQuick
-import "itemCreation.js" as Code
-
-Image {
- id: paletteItem
-
- property string componentFile
- property string image
-
- source: image
-
- MouseArea {
- anchors.fill: parent
-
- onPressed: (mouse)=> Code.startDrag(mouse);
- onPositionChanged: (mouse)=> Code.continueDrag(mouse);
- onReleased: (mouse)=> Code.endDrag(mouse);
- }
-}
diff --git a/examples/qml/dynamicscene/PerspectiveItem.qml b/examples/qml/dynamicscene/PerspectiveItem.qml
deleted file mode 100644
index 8857b92376..0000000000
--- a/examples/qml/dynamicscene/PerspectiveItem.qml
+++ /dev/null
@@ -1,27 +0,0 @@
-// Copyright (C) 2021 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-import QtQuick
-
-Image {
- id: rootItem
-
- property bool created: false
- property string image
-
- property double scaledBottom: y + (height + height*scale) / 2
- property bool onLand: scaledBottom > (window.height / 2 + window.centerOffset)
-
- source: image
- opacity: onLand ? 1 : 0.25
- scale: Math.max((y + height - 250) * 0.01, 0.3)
-
- onCreatedChanged: {
- if (created && !onLand)
- rootItem.destroy();
- else
- z = scaledBottom;
- }
-
- onYChanged: z = scaledBottom;
-}
diff --git a/examples/qml/dynamicscene/Sun.qml b/examples/qml/dynamicscene/Sun.qml
deleted file mode 100644
index e755563eba..0000000000
--- a/examples/qml/dynamicscene/Sun.qml
+++ /dev/null
@@ -1,36 +0,0 @@
-// Copyright (C) 2021 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-import QtQuick
-
-Image {
- id: sun
-
- property bool created: false
- property string image: "images/sun.png"
-
- source: image
- onCreatedChanged: {
- if (created) {
- sun.z = 1; // above the sky but below the ground layer
- window.activeSuns++;
- // once item is created, start moving offscreen
- dropYAnim.duration = (window.height + window.centerOffset - sun.y) * 16;
- dropAnim.running = true;
- } else {
- window.activeSuns--;
- }
- }
-
- SequentialAnimation on y{
- id: dropAnim
- running: false
- NumberAnimation {
- id: dropYAnim
- to: (window.height / 2) + window.centerOffset
- }
- ScriptAction {
- script: { sun.created = false; sun.destroy() }
- }
- }
-}
diff --git a/examples/qml/dynamicscene/doc/images/qml-dynamicscene-example.png b/examples/qml/dynamicscene/doc/images/qml-dynamicscene-example.png
deleted file mode 100644
index 38260a7d3f..0000000000
--- a/examples/qml/dynamicscene/doc/images/qml-dynamicscene-example.png
+++ /dev/null
Binary files differ
diff --git a/examples/qml/dynamicscene/doc/src/dynamicscene.qdoc b/examples/qml/dynamicscene/doc/src/dynamicscene.qdoc
deleted file mode 100644
index a7a3351fdc..0000000000
--- a/examples/qml/dynamicscene/doc/src/dynamicscene.qdoc
+++ /dev/null
@@ -1,10 +0,0 @@
-// Copyright (C) 2017 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
-/*!
- \title QML Example - Dynamic Scene
- \example dynamicscene
- \brief This example demonstrates creating components dynamically.
- \image qml-dynamicscene-example.png
-*/
-
-
diff --git a/examples/qml/dynamicscene/dynamicscene.pro b/examples/qml/dynamicscene/dynamicscene.pro
deleted file mode 100644
index 29a3fa97e2..0000000000
--- a/examples/qml/dynamicscene/dynamicscene.pro
+++ /dev/null
@@ -1,9 +0,0 @@
-TEMPLATE = app
-
-QT += quick qml
-SOURCES += main.cpp
-
-RESOURCES += dynamicscene.qrc
-
-target.path = $$[QT_INSTALL_EXAMPLES]/qml/dynamicscene
-INSTALLS += target
diff --git a/examples/qml/dynamicscene/dynamicscene.qml b/examples/qml/dynamicscene/dynamicscene.qml
deleted file mode 100644
index 62795703c5..0000000000
--- a/examples/qml/dynamicscene/dynamicscene.qml
+++ /dev/null
@@ -1,237 +0,0 @@
-// Copyright (C) 2021 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-import QtQuick
-import QtQuick.Particles
-import QtQuick.Controls
-
-Item {
- id: window
-
- property int activeSuns: 0
- property int centerOffset: 72
-
- height: 480; width: 320
-
-
- MouseArea {
- anchors.fill: parent
- onClicked: window.focus = false;
- }
-
- //This is the message box that pops up when there's an error
- Rectangle {
- id: dialog
-
- opacity: 0
- anchors.centerIn: parent
- width: dialogText.width + 6; height: dialogText.height + 6
- border.color: 'black'
- color: 'lightsteelblue'
- z: 65535 //Arbitrary number chosen to be above all the items, including the scaled perspective ones.
-
- function show(str){
- dialogText.text = str;
- dialogAnim.start();
- }
-
- Label {
- id: dialogText
- x: 3; y: 3
- font.pixelSize: 14
- }
-
- SequentialAnimation {
- id: dialogAnim
- NumberAnimation { target: dialog; property:"opacity"; to: 1; duration: 1000 }
- PauseAnimation { duration: 5000 }
- NumberAnimation { target: dialog; property:"opacity"; to: 0; duration: 1000 }
- }
- }
-
- Item {
- id: scene
- anchors { top: sky.top; bottom: ground.bottom; left: parent.left; right: parent.right}
- z: 10
- }
-
- // sky
- Rectangle {
- id: sky
- anchors { left: parent.left; top: toolbox.bottom; right: parent.right; bottomMargin: -window.centerOffset; bottom: parent.verticalCenter }
- gradient: Gradient {
- GradientStop { id: gradientStopA; position: 0.0; color: "#0E1533" }
- GradientStop { id: gradientStopB; position: 1.0; color: "#437284" }
- }
- }
-
- // stars (when there's no sun)
- ParticleSystem {
- id: particlesystem
- anchors.fill: sky
-
- ImageParticle {
- id: stars
- source: "images/star.png"
- groups: ["stars"]
- opacity: .5
- }
-
- Emitter {
- id: starsemitter
- anchors.fill: parent
- emitRate: parent.width / 50
- lifeSpan: 5000
- group: "stars"
- }
- }
-
- // ground
- Rectangle {
- id: ground
- z: 2 // just above the sun so that the sun can set behind it
- anchors { left: parent.left; top: parent.verticalCenter; topMargin: window.centerOffset; right: parent.right; bottom: parent.bottom }
- gradient: Gradient {
- GradientStop { position: 0.0; color: "ForestGreen" }
- GradientStop { position: 1.0; color: "DarkGreen" }
- }
- }
-
- // top panel
- Rectangle {
- id: toolbox
-
- height: window.centerOffset * 2
- color: "white"
- anchors { right: parent.right; top: parent.top; left: parent.left}
-
- Column {
- anchors.centerIn: parent
- spacing: 8
-
- Label { text: "Drag an item into the scene." }
-
- Rectangle {
- width: palette.width + 10; height: palette.height + 10
- border.color: "black"
-
- Row {
- id: palette
- anchors.centerIn: parent
- spacing: 8
-
- PaletteItem {
- anchors.verticalCenter: parent.verticalCenter
- componentFile: "Sun.qml"
- source: "images/sun.png"
- image: "images/sun.png"
- }
- PaletteItem {
- anchors.verticalCenter: parent.verticalCenter
- componentFile: "GenericSceneItem.qml"
- source: "images/moon.png"
- image: "images/moon.png"
- }
- PaletteItem {
- anchors.verticalCenter: parent.verticalCenter
- componentFile: "PerspectiveItem.qml"
- source: "images/tree_s.png"
- image: "images/tree_s.png"
- }
- PaletteItem {
- anchors.verticalCenter: parent.verticalCenter
- componentFile: "PerspectiveItem.qml"
- source: "images/rabbit_brown.png"
- image: "images/rabbit_brown.png"
- }
- PaletteItem {
- anchors.verticalCenter: parent.verticalCenter
- componentFile: "PerspectiveItem.qml"
- source: "images/rabbit_bw.png"
- image: "images/rabbit_bw.png"
- }
- }
- }
-
- Label { text: "Active Suns: " + window.activeSuns }
- }
- }
-
- //Popup toolbox down the bottom
- Rectangle {
- id: popupToolbox
- z: 1000
- width: parent.width
- height: popupColumn.height + 16
- color: "white"
-
- property bool poppedUp: false
- property int downY: window.height - (createButton.height + 16)
- property int upY: window.height - (popupColumn.height + 16)
- y: poppedUp ? upY : downY
- Behavior on y { NumberAnimation {}}
-
- Column {
- id: popupColumn
- y: 8
- spacing: 8
-
- Row {
- height: createButton.height
- spacing: 8
- Label { text: "Custom QML:"; anchors.verticalCenter: parent.verticalCenter }
- Button {
- id: popupButton
- text: popupToolbox.poppedUp ? "Hide" : "Show"
- onClicked: popupToolbox.poppedUp = !popupToolbox.poppedUp
- }
- Button {
- id: createButton
- text: "Create"
- onClicked: {
- try {
- Qt.createQmlObject(qmlText.text, scene, 'CustomObject');
- } catch(err) {
- dialog.show('Error on line ' + err.qmlErrors[0].lineNumber + '\n' + err.qmlErrors[0].message);
- }
- }
- }
-
- }
-
- Rectangle {
- width: 360; height: 240
-
- TextArea {
- id: qmlText
- anchors.fill: parent; anchors.margins: 5
- readOnly: false
- font.pixelSize: 14
- selectByMouse: true
- wrapMode: TextEdit.WordWrap
-
- text: "import QtQuick\nImage {\n id: smile\n x: 360 * Math.random()\n y: 40 * Math.random() \n source: 'images/face-smile.png'\n NumberAnimation on opacity { \n to: 0; duration: 1500\n }\n Component.onCompleted: smile.destroy(1500);\n}"
- }
- }
- }
- }
-
- //Day state, for when a sun is added to the scene
- states: State {
- name: "Day"
- when: window.activeSuns > 0
-
- PropertyChanges {
- gradientStopA.color: "DeepSkyBlue"
- gradientStopB.color: "SkyBlue"
- stars.opacity: 0
- }
- }
-
- //! [top-level transitions]
- transitions: Transition {
- PropertyAnimation { duration: 3000 }
- ColorAnimation { duration: 3000 }
- }
- //! [top-level transitions]
-}
diff --git a/examples/qml/dynamicscene/dynamicscene.qmlproject b/examples/qml/dynamicscene/dynamicscene.qmlproject
deleted file mode 100644
index 52ac474383..0000000000
--- a/examples/qml/dynamicscene/dynamicscene.qmlproject
+++ /dev/null
@@ -1,16 +0,0 @@
-import QmlProject 1.1
-
-Project {
- mainFile: "dynamicscene.qml"
-
- /* Include .qml, .js, and image files from current directory and subdirectories */
- QmlFiles {
- directory: "."
- }
- JavaScriptFiles {
- directory: "."
- }
- ImageFiles {
- directory: "."
- }
-}
diff --git a/examples/qml/dynamicscene/dynamicscene.qrc b/examples/qml/dynamicscene/dynamicscene.qrc
deleted file mode 100644
index f354fc469a..0000000000
--- a/examples/qml/dynamicscene/dynamicscene.qrc
+++ /dev/null
@@ -1,18 +0,0 @@
-<RCC>
- <qresource prefix="/qt/qml/dynamicscene">
- <file>dynamicscene.qml</file>
- <file>images/face-smile.png</file>
- <file>images/moon.png</file>
- <file>images/NOTE</file>
- <file>images/rabbit_brown.png</file>
- <file>images/rabbit_bw.png</file>
- <file>images/star.png</file>
- <file>images/sun.png</file>
- <file>images/tree_s.png</file>
- <file>GenericSceneItem.qml</file>
- <file>itemCreation.js</file>
- <file>PaletteItem.qml</file>
- <file>PerspectiveItem.qml</file>
- <file>Sun.qml</file>
- </qresource>
-</RCC>
diff --git a/examples/qml/dynamicscene/images/NOTE b/examples/qml/dynamicscene/images/NOTE
deleted file mode 100644
index fcd87f9132..0000000000
--- a/examples/qml/dynamicscene/images/NOTE
+++ /dev/null
@@ -1 +0,0 @@
-Images (except star.png) are from the KDE project.
diff --git a/examples/qml/dynamicscene/images/face-smile.png b/examples/qml/dynamicscene/images/face-smile.png
deleted file mode 100644
index 3d66d72578..0000000000
--- a/examples/qml/dynamicscene/images/face-smile.png
+++ /dev/null
Binary files differ
diff --git a/examples/qml/dynamicscene/images/moon.png b/examples/qml/dynamicscene/images/moon.png
deleted file mode 100644
index 1c0d6066a8..0000000000
--- a/examples/qml/dynamicscene/images/moon.png
+++ /dev/null
Binary files differ
diff --git a/examples/qml/dynamicscene/images/rabbit_brown.png b/examples/qml/dynamicscene/images/rabbit_brown.png
deleted file mode 100644
index ebfdeed332..0000000000
--- a/examples/qml/dynamicscene/images/rabbit_brown.png
+++ /dev/null
Binary files differ
diff --git a/examples/qml/dynamicscene/images/rabbit_bw.png b/examples/qml/dynamicscene/images/rabbit_bw.png
deleted file mode 100644
index 7bff9b92ca..0000000000
--- a/examples/qml/dynamicscene/images/rabbit_bw.png
+++ /dev/null
Binary files differ
diff --git a/examples/qml/dynamicscene/images/star.png b/examples/qml/dynamicscene/images/star.png
deleted file mode 100644
index bdcd36909d..0000000000
--- a/examples/qml/dynamicscene/images/star.png
+++ /dev/null
Binary files differ
diff --git a/examples/qml/dynamicscene/images/sun.png b/examples/qml/dynamicscene/images/sun.png
deleted file mode 100644
index c5fd36ed39..0000000000
--- a/examples/qml/dynamicscene/images/sun.png
+++ /dev/null
Binary files differ
diff --git a/examples/qml/dynamicscene/images/tree_s.png b/examples/qml/dynamicscene/images/tree_s.png
deleted file mode 100644
index 6eac35a729..0000000000
--- a/examples/qml/dynamicscene/images/tree_s.png
+++ /dev/null
Binary files differ
diff --git a/examples/qml/dynamicscene/itemCreation.js b/examples/qml/dynamicscene/itemCreation.js
deleted file mode 100644
index 2829a83410..0000000000
--- a/examples/qml/dynamicscene/itemCreation.js
+++ /dev/null
@@ -1,62 +0,0 @@
-var itemComponent = null;
-var draggedItem = null;
-var startingMouse;
-var posnInWindow;
-
-function startDrag(mouse)
-{
- posnInWindow = paletteItem.mapToItem(window, 0, 0);
- startingMouse = { x: mouse.x, y: mouse.y }
- loadComponent();
-}
-
-//Creation is split into two functions due to an asynchronous wait while
-//possible external files are loaded.
-
-function loadComponent() {
- if (itemComponent != null) { // component has been previously loaded
- createItem();
- return;
- }
-
- itemComponent = Qt.createComponent(paletteItem.componentFile);
- if (itemComponent.status == Component.Loading) //Depending on the content, it can be ready or error immediately
- component.statusChanged.connect(createItem);
- else
- createItem();
-}
-
-function createItem() {
- if (itemComponent.status == Component.Ready && draggedItem == null) {
- draggedItem = itemComponent.createObject(window, {"image": paletteItem.image, "x": posnInWindow.x, "y": posnInWindow.y, "z": 3});
- // make sure created item is above the ground layer
- } else if (itemComponent.status == Component.Error) {
- draggedItem = null;
- console.log("error creating component");
- console.log(itemComponent.errorString());
- }
-}
-
-function continueDrag(mouse)
-{
- if (draggedItem == null)
- return;
-
- draggedItem.x = mouse.x + posnInWindow.x - startingMouse.x;
- draggedItem.y = mouse.y + posnInWindow.y - startingMouse.y;
-}
-
-function endDrag(mouse)
-{
- if (draggedItem == null)
- return;
-
- if (draggedItem.y < toolbox.height) { //Don't drop it in the toolbox
- draggedItem.destroy();
- draggedItem = null;
- } else {
- draggedItem.created = true;
- draggedItem = null;
- }
-}
-
diff --git a/examples/qml/dynamicscene/main.cpp b/examples/qml/dynamicscene/main.cpp
deleted file mode 100644
index e46981848a..0000000000
--- a/examples/qml/dynamicscene/main.cpp
+++ /dev/null
@@ -1,4 +0,0 @@
-// Copyright (C) 2020 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-#include "../../quick/shared/shared.h"
-DECLARATIVE_EXAMPLE_MAIN(dynamicscene/dynamicscene)
diff --git a/examples/qml/locale/locale.qml b/examples/qml/locale/locale.qml
deleted file mode 100644
index 4308dd0c82..0000000000
--- a/examples/qml/locale/locale.qml
+++ /dev/null
@@ -1,101 +0,0 @@
-// Copyright (C) 2017 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-import QtQuick
-
-Rectangle {
- id: root
- width: 320
- height: 480
- color: "lightgray"
-
- component LocaleDelegate: Text {
- required property var modelData
- required property int index
-
- property string locale: modelData
- height: 30
- width: view.width
- text: `${Qt.locale(modelData).name} (${Qt.locale(modelData).nativeCountryName}/${Qt.locale(modelData).nativeLanguageName})`
- MouseArea {
- anchors.fill: parent
- onClicked: view.currentIndex = parent.index
- }
- }
-
- property string locale: (view.currentItem as LocaleDelegate).locale
-
- Text {
- id: title
- text: "Select locale:"
- }
-
- Rectangle {
- id: chooser
- anchors.top: title.bottom
- anchors.topMargin: 5
- width: parent.width-10
- x: 5
- height: parent.height/2 - 10
- color: "#40300030"
- ListView {
- id: view
- clip: true
- focus: true
- anchors.fill: parent
- model: [
- "en_US",
- "en_GB",
- "fi_FI",
- "de_DE",
- "ar_SA",
- "hi_IN",
- "zh_CN",
- "th_TH",
- "fr_FR",
- "nb_NO",
- "sv_SE"
- ]
-
- delegate: LocaleDelegate {}
- highlight: Rectangle {
- height: 30
- color: "#60300030"
- }
- }
- }
-
- Rectangle {
- color: "white"
- anchors.top: chooser.bottom
- anchors.topMargin: 5
- anchors.bottom: parent.bottom
- anchors.bottomMargin: 5
- x: 5; width: parent.width - 10
-
- Column {
- anchors.fill: parent
- spacing: 5
- Text {
- property var date: new Date()
- text: "Date: " + date.toLocaleDateString(Qt.locale(root.locale))
- }
- Text {
- property var date: new Date()
- text: "Time: " + date.toLocaleTimeString(Qt.locale(root.locale))
- }
- Text {
- property var dow: Qt.locale(root.locale).firstDayOfWeek
- text: "First day of week: " + Qt.locale(root.locale).standaloneDayName(dow)
- }
- Text {
- property var num: 10023823
- text: "Number: " + num.toLocaleString(Qt.locale(root.locale))
- }
- Text {
- property var num: 10023823
- text: "Currency: " + num.toLocaleCurrencyString(Qt.locale(root.locale))
- }
- }
- }
-}
diff --git a/examples/qml/networkaccessmanagerfactory/CMakeLists.txt b/examples/qml/networkaccessmanagerfactory/CMakeLists.txt
deleted file mode 100644
index e50a97ab8c..0000000000
--- a/examples/qml/networkaccessmanagerfactory/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(networkaccessmanagerfactory LANGUAGES CXX)
-
-set(CMAKE_AUTOMOC ON)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/qml/networkaccessmanagerfactory")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Gui Network Qml Quick)
-
-qt_add_executable(networkaccessmanagerfactory
- main.cpp
-)
-
-set_target_properties(networkaccessmanagerfactory PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(networkaccessmanagerfactory PUBLIC
- Qt::Core
- Qt::Gui
- Qt::Network
- Qt::Qml
- Qt::Quick
-)
-
-qt_add_qml_module(networkaccessmanagerfactory
- URI Example
- QML_FILES view.qml
- NO_RESOURCE_TARGET_PATH
-)
-
-install(TARGETS networkaccessmanagerfactory
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/qml/networkaccessmanagerfactory/doc/src/networkaccessmanagerfactory.qdoc b/examples/qml/networkaccessmanagerfactory/doc/src/networkaccessmanagerfactory.qdoc
deleted file mode 100644
index 7c46fd0cf7..0000000000
--- a/examples/qml/networkaccessmanagerfactory/doc/src/networkaccessmanagerfactory.qdoc
+++ /dev/null
@@ -1,15 +0,0 @@
-// Copyright (C) 2017 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
-
-/*!
- \example networkaccessmanagerfactory
- \title C++ Extensions: Network Access Manager Factory Example
- \brief Implements a custom network access manager for the QML engine.
-
- This example shows how to use QQmlNetworkAccessManagerFactory to create a QNetworkAccessManager
- with a proxy.
-
- Usage:
- networkaccessmanagerfactory [-host <proxy> -port <port>] [file]
-*/
-
diff --git a/examples/qml/networkaccessmanagerfactory/main.cpp b/examples/qml/networkaccessmanagerfactory/main.cpp
deleted file mode 100644
index dc00d88abe..0000000000
--- a/examples/qml/networkaccessmanagerfactory/main.cpp
+++ /dev/null
@@ -1,97 +0,0 @@
-// Copyright (C) 2017 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include <QCommandLineParser>
-#include <QGuiApplication>
-#include <QNetworkAccessManager>
-#include <QNetworkProxy>
-
-#include <QQmlEngine>
-#include <QQmlNetworkAccessManagerFactory>
-#include <QtQuick/QQuickView>
-
-
-/*
- This example illustrates using a QQmlNetworkAccessManagerFactory to
- create a QNetworkAccessManager with a proxy.
-
- Usage:
- networkaccessmanagerfactory [-host <proxy> -port <port>] [file]
-*/
-
-#if QT_CONFIG(networkproxy)
-static QString proxyHost;
-static int proxyPort = 0;
-#endif // networkproxy
-
-class MyNetworkAccessManagerFactory : public QQmlNetworkAccessManagerFactory
-{
-public:
- QNetworkAccessManager *create(QObject *parent) override;
-};
-
-QNetworkAccessManager *MyNetworkAccessManagerFactory::create(QObject *parent)
-{
- QNetworkAccessManager *nam = new QNetworkAccessManager(parent);
-#if QT_CONFIG(networkproxy)
- if (!proxyHost.isEmpty()) {
- qDebug() << "Created QNetworkAccessManager using proxy" << (proxyHost + ":" + QString::number(proxyPort));
- QNetworkProxy proxy(QNetworkProxy::HttpCachingProxy, proxyHost, proxyPort);
- nam->setProxy(proxy);
- }
-#endif // networkproxy
-
- return nam;
-}
-
-int main(int argc, char ** argv)
-{
- QUrl source("qrc:view.qml");
-
- QGuiApplication app(argc, argv);
-
- QCommandLineParser parser;
-#if QT_CONFIG(networkproxy)
- QCommandLineOption proxyHostOption("host", "The proxy host to use.", "host");
- parser.addOption(proxyHostOption);
- QCommandLineOption proxyPortOption("port", "The proxy port to use.", "port", "0");
- parser.addOption(proxyPortOption);
-#endif // networkproxy
- parser.addPositionalArgument("file", "The file to use.");
- QCommandLineOption helpOption = parser.addHelpOption();
- parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions);
- QStringList arguments = QCoreApplication::arguments();
- if (!parser.parse(arguments)) {
- qWarning() << parser.helpText() << '\n' << parser.errorText();
- exit(1);
- }
- if (parser.isSet(helpOption)) {
- qWarning() << parser.helpText();
- exit(0);
- }
-#if QT_CONFIG(networkproxy)
- if (parser.isSet(proxyHostOption))
- proxyHost = parser.value(proxyHostOption);
- if (parser.isSet(proxyPortOption)) {
- bool ok = true;
- proxyPort = parser.value(proxyPortOption).toInt(&ok);
- if (!ok || proxyPort < 1 || proxyPort > 65535) {
- qWarning() << parser.helpText() << "\nNo valid port given. It should\
- be a number between 1 and 65535";
- exit(1);
- }
- }
-#endif // networkproxy
- if (parser.positionalArguments().count() == 1)
- source = QUrl::fromLocalFile(parser.positionalArguments().first());
-
- QQuickView view;
- MyNetworkAccessManagerFactory networkManagerFactory;
- view.engine()->setNetworkAccessManagerFactory(&networkManagerFactory);
-
- view.setSource(source);
- view.show();
-
- return app.exec();
-}
-
diff --git a/examples/qml/networkaccessmanagerfactory/networkaccessmanagerfactory.pro b/examples/qml/networkaccessmanagerfactory/networkaccessmanagerfactory.pro
deleted file mode 100644
index b4d6d827fd..0000000000
--- a/examples/qml/networkaccessmanagerfactory/networkaccessmanagerfactory.pro
+++ /dev/null
@@ -1,8 +0,0 @@
-TEMPLATE = app
-QT += qml quick network
-
-SOURCES += main.cpp
-RESOURCES += networkaccessmanagerfactory.qrc
-
-target.path = $$[QT_INSTALL_EXAMPLES]/qml/networkaccessmanagerfactory
-INSTALLS = target
diff --git a/examples/qml/networkaccessmanagerfactory/networkaccessmanagerfactory.qmlproject b/examples/qml/networkaccessmanagerfactory/networkaccessmanagerfactory.qmlproject
deleted file mode 100644
index 2bb4016996..0000000000
--- a/examples/qml/networkaccessmanagerfactory/networkaccessmanagerfactory.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/networkaccessmanagerfactory/networkaccessmanagerfactory.qrc b/examples/qml/networkaccessmanagerfactory/networkaccessmanagerfactory.qrc
deleted file mode 100644
index 17e9301471..0000000000
--- a/examples/qml/networkaccessmanagerfactory/networkaccessmanagerfactory.qrc
+++ /dev/null
@@ -1,5 +0,0 @@
-<!DOCTYPE RCC><RCC version="1.0">
-<qresource>
- <file>view.qml</file>
-</qresource>
-</RCC>
diff --git a/examples/qml/networkaccessmanagerfactory/view.qml b/examples/qml/networkaccessmanagerfactory/view.qml
deleted file mode 100644
index f3c845fabd..0000000000
--- a/examples/qml/networkaccessmanagerfactory/view.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 QtQuick
-
-Image {
- width: 200
- height: 100
- source: "http://doc.qt.io/qt-6/images/logo.png"
-}
diff --git a/examples/qml/qml-i18n/CMakeLists.txt b/examples/qml/qml-i18n/CMakeLists.txt
index 83bec4d11b..fd242d3678 100644
--- a/examples/qml/qml-i18n/CMakeLists.txt
+++ b/examples/qml/qml-i18n/CMakeLists.txt
@@ -1,46 +1,45 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# Copyright (C) 2024 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(qml-i18n LANGUAGES CXX)
-set(CMAKE_INCLUDE_CURRENT_DIR ON)
-set(CMAKE_AUTOMOC ON)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/qml/qmli18n")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Quick Qml LinguistTools)
+qt_standard_project_setup(REQUIRES 6.5 I18N_TRANSLATED_LANGUAGES en en_AU fr)
+
qt_add_executable(qmli18n WIN32 MACOSX_BUNDLE main.cpp)
target_link_libraries(qmli18n PRIVATE
- Qt::Core
- Qt::Gui
- Qt::Qml
- Qt::Quick
+ Qt6::Core
+ Qt6::Gui
+ Qt6::Qml
+ Qt6::Quick
)
qt_add_qml_module(qmli18n
- URI i18n
+ URI Translated
QML_FILES
- qml-i18n.qml
- NO_RESOURCE_TARGET_PATH
+ Main.qml
)
qt_add_translations(qmli18n
- TS_FILES
- i18n/base.ts
- i18n/qml_en.ts
- i18n/qml_en_AU.ts
- i18n/qml_fr.ts
+ RESOURCE_PREFIX /qt/qml/Translated/i18n
+ TS_FILE_BASE qml
+ TS_FILE_DIR i18n
)
install(TARGETS qmli18n
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_qml_app_script(
+ TARGET qmli18n
+ OUTPUT_SCRIPT deploy_script
+ MACOS_BUNDLE_POST_BUILD
+ NO_UNSUPPORTED_PLATFORM_ERROR
+ DEPLOY_USER_QML_MODULES_ON_UNSUPPORTED_PLATFORM
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/qml/qml-i18n/qml-i18n.qml b/examples/qml/qml-i18n/Main.qml
index 8d414348dd..8d414348dd 100644
--- a/examples/qml/qml-i18n/qml-i18n.qml
+++ b/examples/qml/qml-i18n/Main.qml
diff --git a/examples/qml/qml-i18n/doc/src/i18n.qdoc b/examples/qml/qml-i18n/doc/src/i18n.qdoc
index 3ea56f6518..6096aa3383 100644
--- a/examples/qml/qml-i18n/doc/src/i18n.qdoc
+++ b/examples/qml/qml-i18n/doc/src/i18n.qdoc
@@ -2,6 +2,7 @@
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
\title Qt Quick I18N
+ \examplecategory {User Interface Components}
\example qml-i18n
\image qml-i18n-example.png
\ingroup examples-linguist
@@ -13,10 +14,10 @@
\section1 Marking Text as Translatable
- In the \c qml-i18n.qml file, use the \c qsTr command to mark UI text as
+ In the \c Main.qml file, use the \c qsTr command to mark UI text as
translatable:
- \quotefromfile qml-i18n/qml-i18n.qml
+ \quotefromfile qml-i18n/Main.qml
\skipto }
\skipto Text
\printuntil )
diff --git a/examples/qml/qml-i18n/i18n/base.ts b/examples/qml/qml-i18n/i18n/base.ts
index 99ceeeb016..17564620e3 100644
--- a/examples/qml/qml-i18n/i18n/base.ts
+++ b/examples/qml/qml-i18n/i18n/base.ts
@@ -2,9 +2,9 @@
<!DOCTYPE TS>
<TS version="2.1" sourcelanguage="en">
<context>
- <name>qml-i18n</name>
+ <name>Main</name>
<message>
- <location filename="../qml-i18n.qml" line="68"/>
+ <location filename="../Main.qml" line="21"/>
<source>Hello</source>
<translation type="unfinished"></translation>
</message>
diff --git a/examples/qml/qml-i18n/i18n/qml_en_AU.ts b/examples/qml/qml-i18n/i18n/qml_en_AU.ts
index feb4f9e9c0..98e1d8649f 100644
--- a/examples/qml/qml-i18n/i18n/qml_en_AU.ts
+++ b/examples/qml/qml-i18n/i18n/qml_en_AU.ts
@@ -2,9 +2,9 @@
<!DOCTYPE TS>
<TS version="2.1" language="en_AU" sourcelanguage="en">
<context>
- <name>qml-i18n</name>
+ <name>Main</name>
<message>
- <location filename="../qml-i18n.qml" line="68"/>
+ <location filename="../Main.qml" line="21"/>
<source>Hello</source>
<translation>G&apos;day</translation>
</message>
diff --git a/examples/qml/qml-i18n/i18n/qml_fr.ts b/examples/qml/qml-i18n/i18n/qml_fr.ts
index c4872e63d0..73c525e535 100644
--- a/examples/qml/qml-i18n/i18n/qml_fr.ts
+++ b/examples/qml/qml-i18n/i18n/qml_fr.ts
@@ -2,9 +2,9 @@
<!DOCTYPE TS>
<TS version="2.1" language="fr" sourcelanguage="en">
<context>
- <name>qml-i18n</name>
+ <name>Main</name>
<message>
- <location filename="../qml-i18n.qml" line="68"/>
+ <location filename="../Main.qml" line="21"/>
<source>Hello</source>
<translation>Bonjour</translation>
</message>
diff --git a/examples/qml/qml-i18n/main.cpp b/examples/qml/qml-i18n/main.cpp
index d03cb05aed..fe20802d3d 100644
--- a/examples/qml/qml-i18n/main.cpp
+++ b/examples/qml/qml-i18n/main.cpp
@@ -1,5 +1,6 @@
-// Copyright (C) 2020 The Qt Company Ltd.
+// Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
#include <QGuiApplication>
#include <QQmlApplicationEngine>
@@ -7,14 +8,11 @@ int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
- const QUrl url(QStringLiteral("qrc:/qml-i18n.qml"));
- QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
- &app, [url](QObject *obj, const QUrl &objUrl) {
- if (!obj && url == objUrl)
- QCoreApplication::exit(-1);
- }, Qt::QueuedConnection);
- engine.load(url);
+ QObject::connect(&engine, &QQmlApplicationEngine::objectCreationFailed,
+ &app, []() { QCoreApplication::exit(-1); },
+ Qt::QueuedConnection);
+ engine.loadFromModule("Translated", "Main");
return app.exec();
}
diff --git a/examples/qml/qml-i18n/qml-i18n.pro b/examples/qml/qml-i18n/qml-i18n.pro
index 847c741b00..0ecfbc01e5 100644
--- a/examples/qml/qml-i18n/qml-i18n.pro
+++ b/examples/qml/qml-i18n/qml-i18n.pro
@@ -8,6 +8,7 @@ RESOURCES += qml-i18n.qrc
target.path = $$[QT_INSTALL_EXAMPLES]/qml/qml-i18n
INSTALLS += target
+QM_FILES_RESOURCE_PREFIX = /qt/qml/Translated/i18n/
CONFIG += lrelease embed_translations
TRANSLATIONS += \
diff --git a/examples/qml/qml-i18n/qml-i18n.qrc b/examples/qml/qml-i18n/qml-i18n.qrc
index 3a505b1665..79ec649894 100644
--- a/examples/qml/qml-i18n/qml-i18n.qrc
+++ b/examples/qml/qml-i18n/qml-i18n.qrc
@@ -1,5 +1,6 @@
<RCC>
- <qresource prefix="/">
- <file>qml-i18n.qml</file>
+ <qresource prefix="/qt/qml/Translated">
+ <file>Main.qml</file>
+ <file>qmldir</file>
</qresource>
</RCC>
diff --git a/examples/qml/qml-i18n/qmldir b/examples/qml/qml-i18n/qmldir
new file mode 100644
index 0000000000..b4773af30e
--- /dev/null
+++ b/examples/qml/qml-i18n/qmldir
@@ -0,0 +1,5 @@
+module Translated
+typeinfo qml-i18n.qmltypes
+depends QtQuick
+prefer :/qt/qml/Translated/
+Main 254.0 Main.qml
diff --git a/examples/qml/qml.pro b/examples/qml/qml.pro
index df73fe0200..f1652820a6 100644
--- a/examples/qml/qml.pro
+++ b/examples/qml/qml.pro
@@ -1,21 +1,8 @@
TEMPLATE = subdirs
QT_FOR_CONFIG += qml
-qtHaveModule(quick) {
- SUBDIRS += \
- qmlextensionplugins \
- xmlhttprequest
-
- qtConfig(qml-network): \
- SUBDIRS += networkaccessmanagerfactory
-}
-
SUBDIRS += \
- referenceexamples \
- tutorials \
- shell
+ tutorials
EXAMPLE_FILES = \
- dynamicscene \
- qml-i18n \
- locale
+ qml-i18n
diff --git a/examples/qml/qmldom/CMakeLists.txt b/examples/qml/qmldom/CMakeLists.txt
deleted file mode 100644
index 1bd1ad0807..0000000000
--- a/examples/qml/qmldom/CMakeLists.txt
+++ /dev/null
@@ -1,37 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.18)
-project(qmldomloadeditwrite LANGUAGES CXX)
-
-set(CMAKE_AUTOMOC ON)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/qml/qmldomloadeditwrite")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Gui Network Qml)
-
-add_compile_definitions(
- QT_QMLTEST_DATADIR="${CMAKE_CURRENT_SOURCE_DIR}/../../../tests/auto/qmldom/domdata"
-)
-
-add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../../../src/qmldom/standalone qmldom)
-
-qt_add_executable(qmldomloadeditwrite
- qmldomloadeditwrite.cpp
-)
-
-target_link_libraries(qmldomloadeditwrite PUBLIC
- Qt::Core
- Qt::Qml
- qmldomlib
-)
-
-install(TARGETS qmldomloadeditwrite
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/qml/qmldom/qmldomloadeditwrite.cpp b/examples/qml/qmldom/qmldomloadeditwrite.cpp
deleted file mode 100644
index 7c7609651b..0000000000
--- a/examples/qml/qmldom/qmldomloadeditwrite.cpp
+++ /dev/null
@@ -1,500 +0,0 @@
-// Copyright (C) 2021 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-// common declarations
-#include "qmldom/qqmldomitem_p.h"
-// comparisons of two DomItems
-#include "qmldom/qqmldomcompare_p.h"
-// field filters to compare only selected fields (ignore for example location changes)
-#include "qmldom/qqmldomfieldfilter_p.h"
-// needed to edit and cast to concrete type (PropertyDefinition, ScriptExpression,...)
-#include "qmldom/qqmldomelements_p.h"
-// cast of the top level items (DomEnvironments,...)
-#include "qmldom/qqmldomtop_p.h"
-
-#include <QtTest/QtTest>
-#include <QCborValue>
-#include <QDebug>
-#include <QLatin1String>
-#include <QLatin1Char>
-#include <QLibraryInfo>
-#include <QDir>
-
-#include <memory>
-
-// everything is in the QQmlJS::Dom namespace
-using namespace QQmlJS::Dom;
-
-int main()
-{
- QString baseDir = QLatin1String(QT_QMLTEST_DATADIR) + QLatin1String("/reformatter");
- QStringList qmltypeDirs =
- QStringList({ baseDir, QLibraryInfo::path(QLibraryInfo::Qml2ImportsPath) });
-
- qDebug() << "Creating an environment loading qml from the directories" << qmltypeDirs;
- qDebug() << "single threaded, no dependencies";
- DomItem env =
- DomEnvironment::create(qmltypeDirs,
- QQmlJS::Dom::DomEnvironment::Option::SingleThreaded
- | QQmlJS::Dom::DomEnvironment::Option::NoDependencies);
-
- QString testFilePath = baseDir + QLatin1String("/file1.qml");
- DomItem tFile; // place where to store the loaded file
- // env.loadBuiltins();
-
- qDebug() << "loading the file" << testFilePath;
- env.loadFile(
- testFilePath, QString(),
- [&tFile](Path, const DomItem &, const DomItem &newIt) {
- tFile = newIt; // callback called when everything is loaded that receives the loaded
- // external file pair (path, oldValue, newValue)
- },
- LoadOption::DefaultLoad);
-
- // trigger the load
- env.loadPendingDependencies();
-
- // # Read only API: DomItem is a generic pointer for read only access to Dom Itmes :)
- {
- // ## declarative json like API
- DomItem qmlFile = tFile.field(Fields::currentItem);
- DomItem imports = qmlFile.field(Fields::imports);
- DomItem qmlObj = qmlFile.field(Fields::components)
- .key(QString())
- .index(0)
- .field(Fields::objects)
- .index(0);
-
- // ### Dump
- // any DomItem can be dumped
- qDebug() << "writing to QDebug dumps that element:" << imports;
- // often the dump is too verbose, and one might want it to a separate file
- QString dumpFilePath =
- QDir(QDir::tempPath())
- .filePath(QFileInfo(testFilePath).baseName() + QLatin1String(".dump.json"));
- qmlFile.dump(dumpFilePath, FieldFilter::defaultFilter());
- qDebug() << "dumped file to" << dumpFilePath;
-
- // ### Paths
- qDebug() << "To identify a DomItem a canonical path can be used:"
- << imports.canonicalPath();
- // a path can be converted to/from strings
- QString pString = imports.canonicalPath().toString();
- Path importsPath = Path::fromString(pString);
- // and loaded again using the .path(somePath) method
- DomItem imports2 = env.path(importsPath);
- Q_ASSERT(imports == imports2);
- // the canonical path is absolute, but you can have relative paths
- Path first = Path::Index(0);
- DomItem firstImport = imports.path(first);
- // an existing path can also be extended
- Path firstImportPath = importsPath.index(0);
- Q_ASSERT(firstImportPath == firstImport.canonicalPath());
- // the normal elements of a path are index, key, field
- // Uppercase static method creates one, lowercase appends to an existing path.
- Path mainComponentPath = Path::Field(Fields::components).key("").index(0);
- DomItem mainComponent = qmlFile.path(mainComponentPath);
- // DomItems have the same methods to access their elements
- DomItem mainComponent2 = qmlFile.field(Fields::components).key("").index(0);
- // two other special ements are root (root element for absolute paths)
- Path topPath = Path::Root(PathRoot::Top);
- Q_ASSERT(topPath == importsPath[0]);
- // the current element performs an operation (tipically a lookup or iteration) at the
- // current path location (not handled here)
- Path lookupPath = Path::Current(PathCurrent::Lookup);
-
- // there are various visit methods to iterate/visit DomItems in particular visitTree
- // which is quite flexible.
- // They normally use callbacks that can return false to stop the iteration.
- // Still often the DomKind specific for loop presentated later are clearer and more
- // convenient
- {
- QDebug dbg = qDebug().noquote().nospace();
- imports.visitTree(
- Path(),
- [&dbg](Path p, const DomItem &el, bool adopted) {
- dbg << QStringLiteral(u" ").repeated(p.length()) << "*" << p.last() << " "
- << domKindToString(el.domKind()) << "(" << el.internalKindStr()
- << ")\n";
- // returning false here stops the whole iteration
- return true;
- },
- VisitOption::Default, // we want a recursive visit visiting also the top and
- // adopted
- [&dbg](Path p, const DomItem &, bool canonicalChild) {
- // returning false here skips that branch
- if (!canonicalChild) {
- dbg << QStringLiteral(u" ").repeated(p.length()) << "+" << p.last()
- << " (adopted, will not recurse)\n";
- } else if (p && p.headIndex(0) % 2 == 1) {
- dbg << QStringLiteral(u" ").repeated(p.length()) << "-" << p.last()
- << " *recursive visit skipped*\n";
- return false; // we skip odd entries in lists;
- } else {
- dbg << QStringLiteral(u" ").repeated(p.length()) << "+" << p.last()
- << "\n";
- }
- return true;
- },
- [&dbg](Path p, const DomItem &, bool) {
- dbg << QStringLiteral(u" ").repeated(p.length()) << "=" << p.last() << "\n";
- return true;
- });
- }
-
- // ### DomKind
- // any DomItem belongs to one of 5 fundamental types
-
- // 1. Object (a C++ object)
- Q_ASSERT(qmlFile.domKind() == DomKind::Object);
- // The underlying type of the c++ object can be found with .internalKind()
- Q_ASSERT(qmlFile.internalKind() == DomType::QmlFile);
- // .initernalKindStr() is a convenience string version of it
- Q_ASSERT(qmlFile.internalKindStr() == u"QmlFile");
- // the object attributes (fields) can be reached using .field(u"filedName")
- // normally one should not use a string, but the Fields:: constant
- DomItem qmlFile2 = tFile.field(Fields::currentItem);
- // all the available fields can be listed via fields()
- qDebug() << "The" << qmlObj.internalKindStr() << "at" << qmlObj.canonicalPath()
- << "has the following fields:" << qmlObj.fields();
- // we can access the underlying C++ object with as<>
- if (const QmlFile *qmlFilePtr = qmlFile.as<QmlFile>())
- qDebug() << "The QmlFile lives at the address" << qmlFilePtr;
- // We can get the shared pointer of the owner type (which for the file is the QmlFile itself
- if (std::shared_ptr<QmlFile> qmlFilePtr = qmlFile.ownerAs<QmlFile>())
- qDebug() << "QmlFile uses shared pointers as ownership method, the underlying address "
- "is the same"
- << qmlFilePtr.get();
-
- // 2. a (Cbor-) Value, i.e a string, number,...
- DomItem fPath = qmlFile.field(Fields::canonicalFilePath);
- Q_ASSERT(fPath.domKind() == DomKind::Value);
- // the Cbor representation of a value can be extracted with .value(), and in this case we
- // can then call toString
- qDebug() << "The filePath DomItem is " << fPath << " and it still 'knows' its path "
- << fPath.canonicalPath() << " but can have it also as value:" << fPath.value()
- << "or even better as string." << fPath.value().toString(QLatin1String("*none*"));
- // a DomItem might have a valid value() even if it is not of type DomKind::Value, indeed
- // CBor maps and lists are mapped to DomKind::Map and DomKind::List, and can be traversed
- // thought that but also have a valid value().
-
- // 3. a list
- Q_ASSERT(imports.domKind() == DomKind::List);
- // the number of elements can be sound with .indexes() and with .index(n) we access each
- // element
- qDebug() << "We have " << imports.indexes() << " imports, and the first is "
- << imports.index(0);
- // If we want to just loop on the elements .values() is the most convenient way
- // technically values *always* works even for objects and maps, iterating on the values
- for (DomItem import : imports.values()) {
- if (const Import *importPtr = import.as<Import>()) {
- if (importPtr->implicit)
- qDebug() << importPtr->uri.toString() << importPtr->version.stringValue();
- }
- }
-
- // 4. a map
- DomItem bindings = qmlObj.field(Fields::bindings);
- Q_ASSERT(bindings.domKind() == DomKind::Map);
- // The keys of the map can be reached either with .keys() or .sortedKeys(), each element
- // with .key(k)
- qDebug() << "bindings";
- for (QString k : bindings.sortedKeys()) {
- for (DomItem b : bindings.key(k).values()) {
- qDebug() << k << ":" << b;
- }
- }
-
- // 5 The empty element
- DomItem empty;
- Q_ASSERT(empty.domKind() == DomKind::Empty);
- // The empty element is the only DomItem that casted to bool returns false, so checking for
- // it can be just an implicit cast to bool
- Q_ASSERT(bindings && !empty);
- // the empty element supports all the previus operations so that one can traverse a non
- // existing path without checking at every element, but only check the result
- DomItem nonExisting = qmlFile.field(u"no-existing").key(u"a").index(0);
- Q_ASSERT(!nonExisting);
-
- // the index operator [] can be used instead of .index/.key/.field, it might be slightly
- // less efficient but works
-
- // find type
- // access type
-
- // ### write out
- // it is possible to write out a qmlFile (actually also parts of it), which will
- // automatically reformat it
- QString reformattedFilePath =
- QDir(QDir::tempPath())
- .filePath(QFileInfo(testFilePath).baseName() + QLatin1String(".qml"));
- DomItem newFile = qmlFile.writeOut(reformattedFilePath);
- qDebug() << "reformatted written at " << reformattedFilePath;
-
- // ## Jumping around
- // ### Generic Methods
- // from a DomItem you do no have just deeper in the tree, you can also go up the hierarch
- // toward the root .container() just goes up one step in the canonicalPath of the object
- Q_ASSERT(imports == firstImport.container());
- // .containingObject() goes up to the containing DomKind::Object, skipping over all Maps and
- // Lists
- Q_ASSERT(qmlFile == firstImport.containingObject());
- // .owner() returns the shared pointer based "owner" object, qmlFile and ScriptExpression
- // are owningItems
- Q_ASSERT(qmlFile == bindings.owner());
- // .top() goes to the top of the tree, i.e the environment (or the universe)
- Q_ASSERT(env == bindings.top());
- // environment is normally the same as top, but making sure it is a actually a
- // DomEnvironment
- Q_ASSERT(env = bindings.environment());
- // the universe is a cache of loaded files which for each file keeps two versions: the
- // latest and the latest valid it can be reached with .universe(), from the universe you
- // cannot get back to the environment.
- Q_ASSERT(env.universe().internalKind() == DomType::DomUniverse);
-
- // ## QML Oriented Methods
- // The Dom model is not for generic json-like structures, so there are methods tailored for
- // Qml and its structure
- // The methods can succeed if there is a clearly defined unique result.
- // sometime there is an obivious, but not necessarily unique choice (tipically going up the
- // hierarchy), for example given a qml file the obvious choice for a component is the root
- // component, but the file might contain other inline components, and for an object with
- // different version exposed (C++ property versioning) the latest version is the natural
- // choice, but other might be available. In these case passing GoTo::MostLikely as argument
- // makes the method to this obivious choice (or possibly even only choice if no other
- // versions/components are actually defined), instead of refusing any potentially ambiguous
- // situation and returning the empty element.
-
- // .fileObject() goes to the object representing the whole file
- // (from either the external object returned by load or from inside the file)
- DomItem fileObject = tFile.fileObject();
- DomItem fileObject2 = imports.fileObject();
- Q_ASSERT(fileObject == fileObject2 && fileObject.internalKind() == DomType::QmlFile);
- // .component() goes to the component object.
- Q_ASSERT(qmlObj.component() == qmlFile.component(GoTo::MostLikely));
- // .pragmas gives access to the pragmas of the current component
- Q_ASSERT(qmlFile.pragmas() == qmlFile.field(Fields::pragmas));
-
- // QmlObject
- // QmlObject if the main to represent the type information (methods, bindings,
- // properties,...) of qml. Please note that QmlObject -> component operation is potentially
- // lossy, when multiple version are exposed, so we represent a type through its root object,
- // not through a component.
-
- // .qmlObject() goes to the current QmlObject
- Q_ASSERT(qmlObj == bindings.qmlObject());
-
- // Given the centrality of QmlObject several of its attributes have convenience methods
- // to access them:
-
- // .children() makes subObjects contained inside a QmlObject accessible
- // note that it is possible to add objects also by directly binding the children or data
- // attribute, those children are not listed here, this accesses only those listed inside
- // the QmlObject
- Q_ASSERT(qmlObj.children() == qmlObj.field(Fields::children));
- DomItem subObj0 = qmlObj.children().index(0);
- // .child(<i>) is a shortcut for .children.index(<i>)
- Q_ASSERT(subObj0 == qmlObj.child(0));
- // rootQmlObject goes to the root qmlObject (unless one reaches an empty element)
- Q_ASSERT(!subObj0 || subObj0.rootQmlObject() == qmlObj);
- // .bindings() returns the bindings defined in the current object
- Q_ASSERT(bindings == qmlObj.bindings());
- DomItem mCompObj = qmlObj.child(0)
- .child(0)
- .bindings()
- .key(u"delegate")
- .index(0)
- .field(Fields::value)
- .child(1);
- // .methods() gives methods definitions and signals
- DomItem methods = mCompObj.methods();
- qDebug() << "mCompObj methods:";
- for (QString methodName : methods.sortedKeys()) {
- for (DomItem method : methods.key(methodName).values()) {
- if (const MethodInfo *methodPtr = method.as<MethodInfo>()) {
- Q_ASSERT(methodName == methodPtr->name);
- qDebug() << " " << methodPtr->name << methodPtr->methodType;
- }
- }
- }
- qDebug() << "mCompObj propertyDefs:";
- // .propertyDefs() returns the properties defined in the current object
- DomItem pDefs = mCompObj.propertyDefs();
- for (QString pDefName : pDefs.sortedKeys()) {
- for (DomItem pDef : pDefs.key(pDefName).values()) {
- if (const PropertyDefinition *pDefPtr = pDef.as<PropertyDefinition>()) {
- Q_ASSERT(pDefName == pDefPtr->name);
- qDebug() << " " << pDefPtr->name << pDefPtr->typeName;
- }
- }
- }
- // binding and property definitions are about the ones defined in the current object
- // often one is interested also to the inherited properties.
- // Here PropertyInfo helps, it list all the definitions and bindings for a given property
- // in the inheritance order (local definitions, parent definitions, parent parent
- // definitions,...)
- // .propertyInfos() gives access in the usual way (through a DomItem)
- DomItem propertyInfos = mCompObj.propertyInfos();
- // .propertyInfoWithName(<name>) directly accesses one
- PropertyInfo pInfo = mCompObj.propertyInfoWithName(QStringLiteral(u"a"));
- qDebug() << "bindings" << pInfo.bindings;
- // .propertyInfoNames() gives the names of the properties
- Q_ASSERT(propertyInfos.keys() == mCompObj.propertyInfoNames());
-
- // .globalScope() goes to the globa scope object
- Q_ASSERT(qmlObj.globalScope().internalKind() == DomType::GlobalScope);
- // and scope to the containing scope
- Q_ASSERT(bindings.scope() == qmlObj);
- }
- // mutate & edit
- {
- // DomItem handles read-only access, but if one wants to change something it cannot be used.
- // MutableDomItem can be initialized with a DomItem, and provides also the methods to modify
- // the item. It keeps the OwningItem and the path to the current item.
- // Mutability can invalidate pointers to non owning items (and thus DomItem).
- // For this reason one should not modify something that other code can have a DomItem
- // pointer to, the best practice is to make shared object immutable and never change them.
- // One should modify only a copy that is used only by a single thread, and
- // do not shared untils all modifications are done.
- // A MutableItem stays valid (or becomes Empty), but stays safe to use
- //
- // Assuming one guarantees that editing is ok, doing it in practice is just about using
- // MutableDomItem instead of DomItem
- // It is possible to simply initialize a mutable item with a DomItem
- DomItem origFile = tFile.fileObject();
- MutableDomItem myFile0(origFile);
- // Normally it is better to have a separate environment. Is possible to avoid re-reading
- // the files already read by sharing the Universe between two environments.
- // But normally it is better and just as safe to work on a copy, so that one can be sure
- // that no DomItem is kept by other code gets invalidated. The .makeCopy creates a deep
- // copy, and by default (DomItem::CopyOption::EnvConnected) creates an environment which to
- // takes all non local elements from the current environment (its parent environment) but
- // replaces the file object with the copy. When finished one can replace the file object of
- // the parent with the new one using .commitToBase().
- MutableDomItem myFile = origFile.makeCopy();
- Q_ASSERT(myFile.ownerAs<QmlFile>()
- && myFile.ownerAs<QmlFile>() != myFile0.ownerAs<QmlFile>());
- Q_ASSERT(myFile.environment().ownerAs<DomEnvironment>()
- && myFile.environment().ownerAs<DomEnvironment>()
- != myFile0.environment().ownerAs<DomEnvironment>());
- // we can check that the two files are really identical (.item() give back the DomItem of
- // a MutableDomItem
- Q_ASSERT(domCompareStrList(origFile, myFile, FieldFilter::compareFilter()).isEmpty());
- // MutableDomItem has the same methods as DomItem
- MutableDomItem qmlObj = myFile.qmlObject(GoTo::MostLikely);
- MutableDomItem qmlObj2 = myFile.field(Fields::components)
- .key(QString())
- .index(0)
- .field(Fields::objects)
- .index(0);
- Q_ASSERT(qmlObj && qmlObj == qmlObj2);
- qDebug() << "mutable qmlObj has canonicalPath " << qmlObj.canonicalPath();
- // but it adds methods to add
- // * new PropertyDefinitions
- PropertyDefinition b;
- b.name = QLatin1String("xx");
- b.typeName = QLatin1String("int");
- // if we make t true we also have to give a value...
- MutableDomItem addedPDef = qmlObj.addPropertyDef(b);
- qDebug() << "added property definition at:" << addedPDef.pathFromOwner();
- // * new bindings
- MutableDomItem addedBinding0 = qmlObj.addBinding(
- Binding("height",
- std::shared_ptr<ScriptExpression>(new ScriptExpression(
- QStringLiteral(u"243"),
- ScriptExpression::ExpressionType::BindingExpression))));
- // by default addBinding, addPropertyDef and addMethod have the AddOption::Override
- // to make it more difficult to create invalid documents, so that only the
- // following binding remains (where we use the convenience constructor that constucts
- // the ScriptExpression internally
- MutableDomItem addedBinding = qmlObj.addBinding(Binding("height", QStringLiteral(u"242")));
- qDebug() << "added binding at:" << addedBinding.pathFromOwner();
- // * new methods
- MethodInfo mInfo;
- mInfo.name = QLatin1String("foo2");
- MethodParameter param;
- param.name = QLatin1String("x");
- mInfo.parameters.append(param);
- mInfo.setCode(QLatin1String("return 4*10+2 - x"));
- // we can change the added binding
- addedBinding.setCode(QLatin1String("245"));
- MutableDomItem addedMethod = qmlObj.addMethod(mInfo);
- qDebug() << "added method at:" << addedMethod.pathFromOwner();
- // * new QmlObjects
- QmlObject subObj;
- subObj.setName(QLatin1String("Item"));
- MutableDomItem addedSubObj = qmlObj.addChild(subObj);
- qDebug() << "added subObject at:" << addedMethod.pathFromOwner();
- // It is possible to modify the content of objects, using the mutableAs method
- if (PropertyDefinition *addedPDefPtr = addedPDef.mutableAs<PropertyDefinition>()) {
- addedPDefPtr->isRequired = true;
- }
- MutableDomItem firstChild = qmlObj.child(0);
- qDebug() << "firstChild:" << firstChild;
- // It is possible remove objects
- if (QmlObject *qmlObjPtr = qmlObj.mutableAs<QmlObject>()) {
- QList<QmlObject> children = qmlObjPtr->children();
- children.removeAt(0);
- qmlObjPtr->setChildren(children);
- }
- // But as MutableDomItem does not keep the identity, just the same position, the addedSubObj
- // becomes invalid (and firstChild changes)
- qDebug() << "after removal firstChild:" << firstChild;
- qDebug() << "addedSubObj becomes invalid:" << addedSubObj;
- qDebug() << "But the last object is the added one:"
- << qmlObj.child(qmlObj.children().indexes() - 1);
-
- // now origFile are different
- Q_ASSERT(!domCompareStrList(origFile, myFile, FieldFilter::compareFilter()).isEmpty());
- // and we can look at the places where they differ
- qDebug().noquote().nospace()
- << "Edits introduced the following diffs (ignoring file locations"
- << " and thus whitespace/reformatting changes):\n"
- << domCompareStrList(origFile, myFile, FieldFilter::noLocationFilter(),
- DomCompareStrList::AllDiffs)
- .join(QString());
-
- QString reformattedFilePath =
- QDir(QDir::tempPath())
- .filePath(QStringLiteral(u"edited") + QFileInfo(testFilePath).baseName()
- + QLatin1String(".qml"));
- MutableDomItem reformattedEditedFile = myFile.writeOut(reformattedFilePath);
- // the reformatted edited file might be different from the edited file
- // but the differences are just in file location/formatting
- Q_ASSERT(domCompareStrList(myFile, reformattedEditedFile, FieldFilter::noLocationFilter())
- .isEmpty());
-
- qDebug() << "The edited file was written at " << reformattedFilePath;
- QString dumpFilePath =
- QDir(QDir::tempPath())
- .filePath(QStringLiteral(u"edited0") + QFileInfo(testFilePath).baseName()
- + QLatin1String(".dump.json"));
- myFile.dump(dumpFilePath);
- qDebug() << "The non reformatted edited file was dumped at " << dumpFilePath;
- QString reformattedDumpFilePath =
- QDir(QDir::tempPath())
- .filePath(QStringLiteral(u"edited") + QFileInfo(testFilePath).baseName()
- + QLatin1String(".dump.json"));
- reformattedEditedFile.dump(reformattedDumpFilePath);
- qDebug() << "The edited file was dumped at " << reformattedDumpFilePath;
- // The top environment still contains the original loaded file
- Q_ASSERT(origFile.ownerAs<QmlFile>() != reformattedEditedFile.ownerAs<QmlFile>());
- Q_ASSERT(tFile.fileObject().refreshed().ownerAs<QmlFile>());
- Q_ASSERT(tFile.fileObject().refreshed().ownerAs<QmlFile>() == origFile.ownerAs<QmlFile>());
- Q_ASSERT(tFile.fileObject().ownerAs<QmlFile>() == origFile.ownerAs<QmlFile>());
- Q_ASSERT(tFile.fileObject().refreshed().ownerAs<QmlFile>()
- != reformattedEditedFile.ownerAs<QmlFile>());
- // we can commit the reformatted file
- if (!reformattedEditedFile.commitToBase()) {
- qWarning() << "No reformatted file to commit";
- }
- // myFile might not be the same (If and updated check is requested, not the case here)
- if (myFile.ownerAs<QmlFile>() != reformattedEditedFile.ownerAs<QmlFile>()
- && !myFile.commitToBase()) {
- qWarning() << "Could not commit edited file";
- }
- // but refreshing it (looking up its canonical path) we always find the updated file
- Q_ASSERT(myFile.refreshed().ownerAs<QmlFile>() == reformattedEditedFile.ownerAs<QmlFile>());
- Q_ASSERT(tFile.fileObject().refreshed().ownerAs<QmlFile>()
- == reformattedEditedFile.ownerAs<QmlFile>());
- }
-}
diff --git a/examples/qml/qmlextensionplugins/CMakeLists.txt b/examples/qml/qmlextensionplugins/CMakeLists.txt
deleted file mode 100644
index 753f05b173..0000000000
--- a/examples/qml/qmlextensionplugins/CMakeLists.txt
+++ /dev/null
@@ -1,61 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(qmlqtimeexample LANGUAGES CXX)
-
-set(CMAKE_AUTOMOC ON)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/qml/qmlextensionplugins/imports/TimeExample")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Gui Qml)
-
-#![0]
-set(qml_files
- imports/TimeExample/Clock.qml
-)
-
-set(images
- imports/TimeExample/center.png
- imports/TimeExample/clock.png
- imports/TimeExample/hour.png
- imports/TimeExample/minute.png
-)
-#![0]
-
-foreach(file IN LISTS qml_files images)
- get_filename_component(filename ${file} NAME)
- set_source_files_properties(${file} PROPERTIES QT_RESOURCE_ALIAS ${filename})
-endforeach()
-
-#![1]
-qt_add_qml_module(qmlqtimeexample
- OUTPUT_DIRECTORY imports/TimeExample
- URI "TimeExample"
- SOURCES timemodel.cpp timemodel.h
- AUTO_RESOURCE_PREFIX
- QML_FILES ${qml_files}
- RESOURCES ${images}
-)
-#![1]
-
-set_target_properties(qmlqtimeexample PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(qmlqtimeexample PUBLIC
- Qt::Core
- Qt::Gui
- Qt::Qml
-)
-
-install(TARGETS qmlqtimeexample
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/qml/qmlextensionplugins/doc/images/qml-plugins-example.png b/examples/qml/qmlextensionplugins/doc/images/qml-plugins-example.png
deleted file mode 100644
index c2d4886ea2..0000000000
--- a/examples/qml/qmlextensionplugins/doc/images/qml-plugins-example.png
+++ /dev/null
Binary files differ
diff --git a/examples/qml/qmlextensionplugins/doc/src/qmlpluginex.qdoc b/examples/qml/qmlextensionplugins/doc/src/qmlpluginex.qdoc
deleted file mode 100644
index 80f39e36ce..0000000000
--- a/examples/qml/qmlextensionplugins/doc/src/qmlpluginex.qdoc
+++ /dev/null
@@ -1,43 +0,0 @@
-// Copyright (C) 2021 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
-
-/*!
- \title QML Plugin Example
- \example qmlextensionplugins
-
- \brief This example creates a C++ plugin extension by subclassing QQmlEngineExtensionPlugin.
-
- \image qml-plugins-example.png
-
- To run this example, use the following commands on the prompt:
-
- \if defined(onlinedocs)
- \tab {build-qt-app}{tab-cmake}{CMake}{checked}
- \tab {build-qt-app}{tab-qmake}{qmake}{}
- \tabcontent {tab-cmake}
- \else
- \section1 Using CMake
- \endif
- \badcode \QtVersion
- cmake -DCMAKE_PREFIX_PATH=path/to/Qt/\1/your_platform -S <source-dir> -B <build-dir> -G Ninja
- cd path/to/build/dir
- ninja
- qml -I imports plugins.qml
- \endcode
- For more information about building on the command line using CMake,
- see \l {Building projects on the command line}.
- \if defined(onlinedocs)
- \endtabcontent
- \tabcontent {tab-qmake}
- \else
- \section1 Using qmake
- \endif
- \badcode
- qmake
- make
- qml -I imports plugins.qml
- \endcode
- \if defined(onlinedocs)
- \endtabcontent
- \endif
-*/
diff --git a/examples/qml/qmlextensionplugins/imports/TimeExample/Clock.qml b/examples/qml/qmlextensionplugins/imports/TimeExample/Clock.qml
deleted file mode 100644
index b071e2e031..0000000000
--- a/examples/qml/qmlextensionplugins/imports/TimeExample/Clock.qml
+++ /dev/null
@@ -1,51 +0,0 @@
-// Copyright (C) 2017 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-import QtQuick
-
-Rectangle {
- id: clock
- width: 200; height: 200; color: "gray"
-
- property alias city: cityLabel.text
- property variant hours
- property variant minutes
- property variant shift : 0
-
- Image { id: background; source: "clock.png" }
-
- Image {
- x: 92.5; y: 27
- source: "hour.png"
- transform: Rotation {
- id: hourRotation
- origin.x: 7.5; origin.y: 73;
- angle: (clock.hours * 30) + (clock.minutes * 0.5)
- Behavior on angle {
- SpringAnimation{ spring: 2; damping: 0.2; modulus: 360 }
- }
- }
- }
-
- Image {
- x: 93.5; y: 17
- source: "minute.png"
- transform: Rotation {
- id: minuteRotation
- origin.x: 6.5; origin.y: 83;
- angle: clock.minutes * 6
- Behavior on angle {
- SpringAnimation{ spring: 2; damping: 0.2; modulus: 360 }
- }
- }
- }
-
- Image {
- anchors.centerIn: background; source: "center.png"
- }
-
- Text {
- id: cityLabel; font.bold: true; font.pixelSize: 14; y:200; color: "white"
- anchors.horizontalCenter: parent.horizontalCenter
- }
-}
diff --git a/examples/qml/qmlextensionplugins/imports/TimeExample/center.png b/examples/qml/qmlextensionplugins/imports/TimeExample/center.png
deleted file mode 100644
index 7fbd802a44..0000000000
--- a/examples/qml/qmlextensionplugins/imports/TimeExample/center.png
+++ /dev/null
Binary files differ
diff --git a/examples/qml/qmlextensionplugins/imports/TimeExample/clock.png b/examples/qml/qmlextensionplugins/imports/TimeExample/clock.png
deleted file mode 100644
index 462edacc0e..0000000000
--- a/examples/qml/qmlextensionplugins/imports/TimeExample/clock.png
+++ /dev/null
Binary files differ
diff --git a/examples/qml/qmlextensionplugins/imports/TimeExample/hour.png b/examples/qml/qmlextensionplugins/imports/TimeExample/hour.png
deleted file mode 100644
index 9f33fc5d48..0000000000
--- a/examples/qml/qmlextensionplugins/imports/TimeExample/hour.png
+++ /dev/null
Binary files differ
diff --git a/examples/qml/qmlextensionplugins/imports/TimeExample/minute.png b/examples/qml/qmlextensionplugins/imports/TimeExample/minute.png
deleted file mode 100644
index e2f216c897..0000000000
--- a/examples/qml/qmlextensionplugins/imports/TimeExample/minute.png
+++ /dev/null
Binary files differ
diff --git a/examples/qml/qmlextensionplugins/imports/TimeExample/qmldir b/examples/qml/qmlextensionplugins/imports/TimeExample/qmldir
deleted file mode 100644
index 252e662e12..0000000000
--- a/examples/qml/qmlextensionplugins/imports/TimeExample/qmldir
+++ /dev/null
@@ -1,3 +0,0 @@
-module TimeExample
-Clock 1.0 Clock.qml
-plugin qmlqtimeexampleplugin
diff --git a/examples/qml/qmlextensionplugins/plugin.cpp b/examples/qml/qmlextensionplugins/plugin.cpp
deleted file mode 100644
index 066d284a5e..0000000000
--- a/examples/qml/qmlextensionplugins/plugin.cpp
+++ /dev/null
@@ -1,15 +0,0 @@
-// Copyright (C) 2017 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include <QtQml/QQmlEngineExtensionPlugin>
-#include <qdebug.h>
-
-//![plugin]
-class QExampleQmlPlugin : public QQmlEngineExtensionPlugin
-{
- Q_OBJECT
- Q_PLUGIN_METADATA(IID QQmlEngineExtensionInterface_iid)
-};
-//![plugin]
-
-#include "plugin.moc"
diff --git a/examples/qml/qmlextensionplugins/plugins.qml b/examples/qml/qmlextensionplugins/plugins.qml
deleted file mode 100644
index 55e8903400..0000000000
--- a/examples/qml/qmlextensionplugins/plugins.qml
+++ /dev/null
@@ -1,16 +0,0 @@
-// Copyright (C) 2017 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-//![0]
-import TimeExample // import types from the plugin
-
-Clock { // this class is defined in QML (imports/TimeExample/Clock.qml)
-
- Time { // this class is defined in C++ (plugin.cpp)
- id: time
- }
-
- hours: time.hour
- minutes: time.minute
-
-}
-//![0]
diff --git a/examples/qml/qmlextensionplugins/plugins.qmlproject b/examples/qml/qmlextensionplugins/plugins.qmlproject
deleted file mode 100644
index c2de5f5703..0000000000
--- a/examples/qml/qmlextensionplugins/plugins.qmlproject
+++ /dev/null
@@ -1,18 +0,0 @@
-import QmlProject 1.1
-
-Project {
- mainFile: "plugins.qml"
-
- /* Include .qml, .js, and image files from current directory and subdirectories */
- QmlFiles {
- directory: "."
- }
- JavaScriptFiles {
- directory: "."
- }
- ImageFiles {
- directory: "."
- }
-
- importPaths: [ "imports" ]
-}
diff --git a/examples/qml/qmlextensionplugins/qmlextensionplugins.pro b/examples/qml/qmlextensionplugins/qmlextensionplugins.pro
deleted file mode 100644
index c074b8d671..0000000000
--- a/examples/qml/qmlextensionplugins/qmlextensionplugins.pro
+++ /dev/null
@@ -1,46 +0,0 @@
-TEMPLATE = lib
-CONFIG += plugin qmltypes
-QT += qml
-
-QML_IMPORT_NAME = TimeExample
-QML_IMPORT_MAJOR_VERSION = 1
-
-DESTDIR = imports/$$QML_IMPORT_NAME
-TARGET = qmlqtimeexampleplugin
-QMLTYPES_FILENAME = $$DESTDIR/plugins.qmltypes
-
-SOURCES += \
- plugin.cpp \
- timemodel.cpp
-
-HEADERS += \
- timemodel.h
-
-PLUGINFILES = \
- imports/$$QML_IMPORT_NAME/qmldir \
- imports/$$QML_IMPORT_NAME/center.png \
- imports/$$QML_IMPORT_NAME/clock.png \
- imports/$$QML_IMPORT_NAME/Clock.qml \
- imports/$$QML_IMPORT_NAME/hour.png \
- imports/$$QML_IMPORT_NAME/minute.png
-
-target.path = $$[QT_INSTALL_EXAMPLES]/qml/qmlextensionplugins/imports/$$QML_IMPORT_NAME
-
-pluginfiles_copy.files = $$PLUGINFILES
-pluginfiles_copy.path = $$DESTDIR
-
-pluginfiles_install.files = $$PLUGINFILES $$OUT_PWD/$$DESTDIR/plugins.qmltypes
-pluginfiles_install.path = $$[QT_INSTALL_EXAMPLES]/qml/qmlextensionplugins/imports/$$QML_IMPORT_NAME
-
-qml_copy.files = plugins.qml plugins.qmlproject
-qml_copy.path = $$OUT_PWD
-
-qml_install.files = plugins.qml plugins.qmlproject
-qml_install.path = $$[QT_INSTALL_EXAMPLES]/qml/qmlextensionplugins
-
-INSTALLS += target qml_install pluginfiles_install
-COPIES += qml_copy pluginfiles_copy
-
-OTHER_FILES += $$PLUGINFILES plugins.qml
-
-CONFIG += install_ok # Do not cargo-cult this!
diff --git a/examples/qml/qmlextensionplugins/timemodel.cpp b/examples/qml/qmlextensionplugins/timemodel.cpp
deleted file mode 100644
index a94a7e773d..0000000000
--- a/examples/qml/qmlextensionplugins/timemodel.cpp
+++ /dev/null
@@ -1,51 +0,0 @@
-// Copyright (C) 2017 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "timemodel.h"
-
-int TimeModel::instances=0;
-MinuteTimer *TimeModel::timer=nullptr;
-
-void MinuteTimer::start()
-{
- if (!timer.isActive()) {
- time = QTime::currentTime();
- timer.start(60000-time.second()*1000, this);
- }
-}
-
-void MinuteTimer::stop()
-{
- timer.stop();
-}
-
-void MinuteTimer::timerEvent(QTimerEvent *)
-{
- QTime now = QTime::currentTime();
- if (now.second() == 59 && now.minute() == time.minute() && now.hour() == time.hour()) {
- // just missed time tick over, force it, wait extra 0.5 seconds
- time = time.addSecs(60);
- timer.start(60500, this);
- } else {
- time = now;
- timer.start(60000-time.second()*1000, this);
- }
- emit timeChanged();
-}
-
-TimeModel::TimeModel(QObject *parent) : QObject(parent)
-{
- if (++instances == 1) {
- if (!timer)
- timer = new MinuteTimer(QCoreApplication::instance());
- connect(timer, &MinuteTimer::timeChanged, this, &TimeModel::timeChanged);
- timer->start();
- }
-}
-
-TimeModel::~TimeModel()
-{
- if (--instances == 0) {
- timer->stop();
- }
-}
diff --git a/examples/qml/qmlextensionplugins/timemodel.h b/examples/qml/qmlextensionplugins/timemodel.h
deleted file mode 100644
index 2c27a6dada..0000000000
--- a/examples/qml/qmlextensionplugins/timemodel.h
+++ /dev/null
@@ -1,64 +0,0 @@
-// Copyright (C) 2017 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef TIMEMODEL_H
-#define TIMEMODEL_H
-
-#include <QtQml/qqml.h>
-#include <QtCore/qdatetime.h>
-#include <QtCore/qbasictimer.h>
-#include <QtCore/qcoreapplication.h>
-
-// Implements a "TimeModel" class with hour and minute properties
-// that change on-the-minute yet efficiently sleep the rest
-// of the time.
-
-class MinuteTimer : public QObject
-{
- Q_OBJECT
-public:
- MinuteTimer(QObject *parent) : QObject(parent) {}
-
- void start();
- void stop();
-
- int hour() const { return time.hour(); }
- int minute() const { return time.minute(); }
-
-signals:
- void timeChanged();
-
-protected:
- void timerEvent(QTimerEvent *) override;
-
-private:
- QTime time;
- QBasicTimer timer;
-};
-
-//![0]
-class TimeModel : public QObject
-{
- Q_OBJECT
- Q_PROPERTY(int hour READ hour NOTIFY timeChanged)
- Q_PROPERTY(int minute READ minute NOTIFY timeChanged)
- QML_NAMED_ELEMENT(Time)
-//![0]
-
-public:
- TimeModel(QObject *parent=nullptr);
- ~TimeModel() override;
-
- int minute() const { return timer->minute(); }
- int hour() const { return timer->hour(); }
-
-signals:
- void timeChanged();
-
-private:
- QTime t;
- static MinuteTimer *timer;
- static int instances;
-};
-
-#endif // TIMEMODEL_H
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/adding/person.h b/examples/qml/referenceexamples/adding/person.h
deleted file mode 100644
index 867927ee2b..0000000000
--- a/examples/qml/referenceexamples/adding/person.h
+++ /dev/null
@@ -1,32 +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>
-
-//![0]
-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;
-};
-//![0]
-
-#endif // PERSON_H
diff --git a/examples/qml/referenceexamples/attached/CMakeLists.txt b/examples/qml/referenceexamples/attached/CMakeLists.txt
deleted file mode 100644
index ce4ff3e80f..0000000000
--- a/examples/qml/referenceexamples/attached/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(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")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Gui Qml)
-
-qt_add_executable(attached
- birthdayparty.cpp birthdayparty.h
- main.cpp
- person.cpp person.h
-)
-
-set_target_properties(attached PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(attached PUBLIC
- Qt::Core
- Qt::Gui
- Qt::Qml
-)
-
-qt_add_qml_module(attached
- URI People
- QML_FILES example.qml
- NO_RESOURCE_TARGET_PATH
-)
-
-install(TARGETS attached
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
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/attached/person.h b/examples/qml/referenceexamples/attached/person.h
deleted file mode 100644
index 9c617ee9ab..0000000000
--- a/examples/qml/referenceexamples/attached/person.h
+++ /dev/null
@@ -1,75 +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)
- Q_PROPERTY(ShoeDescription *shoe READ shoe)
- 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/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/CMakeLists.txt b/examples/qml/referenceexamples/coercion/CMakeLists.txt
deleted file mode 100644
index 495b266f2f..0000000000
--- a/examples/qml/referenceexamples/coercion/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(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")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Qml)
-
-qt_add_executable(coercion
- birthdayparty.cpp birthdayparty.h
- main.cpp
- person.cpp person.h
-)
-
-set_target_properties(coercion PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(coercion PUBLIC
- Qt::Core
- Qt::Qml
-)
-
-qt_add_qml_module(coercion
- URI People
- QML_FILES example.qml
- NO_RESOURCE_TARGET_PATH
-)
-
-install(TARGETS coercion
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
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/CMakeLists.txt b/examples/qml/referenceexamples/default/CMakeLists.txt
deleted file mode 100644
index 681085f386..0000000000
--- a/examples/qml/referenceexamples/default/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(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")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Qml)
-
-qt_add_executable(default
- birthdayparty.cpp birthdayparty.h
- main.cpp
- person.cpp person.h
-)
-
-set_target_properties(default PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(default PUBLIC
- Qt::Core
- Qt::Qml
-)
-
-qt_add_qml_module(default
- URI People
- QML_FILES example.qml
- NO_RESOURCE_TARGET_PATH
-)
-
-install(TARGETS default
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
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/CMakeLists.txt b/examples/qml/referenceexamples/grouped/CMakeLists.txt
deleted file mode 100644
index b1c7587b58..0000000000
--- a/examples/qml/referenceexamples/grouped/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(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")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Gui Qml)
-
-qt_add_executable(grouped
- birthdayparty.cpp birthdayparty.h
- main.cpp
- person.cpp person.h
-)
-
-set_target_properties(grouped PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(grouped PUBLIC
- Qt::Core
- Qt::Gui
- Qt::Qml
-)
-
-qt_add_qml_module(grouped
- URI People
- QML_FILES example.qml
- NO_RESOURCE_TARGET_PATH
-)
-
-install(TARGETS grouped
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
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/grouped/person.h b/examples/qml/referenceexamples/grouped/person.h
deleted file mode 100644
index b5fa469025..0000000000
--- a/examples/qml/referenceexamples/grouped/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/methods/CMakeLists.txt b/examples/qml/referenceexamples/methods/CMakeLists.txt
deleted file mode 100644
index 57c0733723..0000000000
--- a/examples/qml/referenceexamples/methods/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(methods LANGUAGES CXX)
-
-set(CMAKE_AUTOMOC ON)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/qml/referenceexamples/methods")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Qml)
-
-qt_add_executable(methods
- birthdayparty.cpp birthdayparty.h
- main.cpp
- person.cpp person.h
-)
-
-set_target_properties(methods PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(methods PUBLIC
- Qt::Core
- Qt::Qml
-)
-
-qt_add_qml_module(methods
- URI People
- QML_FILES example.qml
- NO_RESOURCE_TARGET_PATH
-)
-
-install(TARGETS methods
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
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/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/person.h b/examples/qml/referenceexamples/signal/person.h
deleted file mode 100644
index 9c617ee9ab..0000000000
--- a/examples/qml/referenceexamples/signal/person.h
+++ /dev/null
@@ -1,75 +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)
- Q_PROPERTY(ShoeDescription *shoe READ shoe)
- 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/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/CMakeLists.txt b/examples/qml/referenceexamples/valuesource/CMakeLists.txt
deleted file mode 100644
index 266bb2b754..0000000000
--- a/examples/qml/referenceexamples/valuesource/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(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")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Gui Qml)
-
-qt_add_executable(valuesource
- birthdayparty.cpp birthdayparty.h
- happybirthdaysong.cpp happybirthdaysong.h
- main.cpp
- person.cpp person.h
-)
-
-set_target_properties(valuesource PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(valuesource PUBLIC
- Qt::Core
- Qt::Gui
- Qt::Qml
-)
-
-qt_add_qml_module(valuesource
- URI People
- QML_FILES example.qml
- NO_RESOURCE_TARGET_PATH
-)
-
-install(TARGETS valuesource
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
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/shell/CMakeLists.txt b/examples/qml/shell/CMakeLists.txt
deleted file mode 100644
index b5bda8a4db..0000000000
--- a/examples/qml/shell/CMakeLists.txt
+++ /dev/null
@@ -1,47 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(shell LANGUAGES CXX)
-
-set(CMAKE_AUTOMOC ON)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/qml/shell")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Qml)
-
-qt_add_executable(shell
- main.cpp
-)
-
-set_target_properties(shell PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(shell PUBLIC
- Qt::Core
- Qt::Qml
-)
-
-if(WIN32)
- set_target_properties(shell PROPERTIES
- WIN32_EXECUTABLE FALSE
- )
-endif()
-
-if(APPLE)
- set_target_properties(shell PROPERTIES
- MACOSX_BUNDLE FALSE
- )
-endif()
-
-install(TARGETS shell
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/qml/shell/main.cpp b/examples/qml/shell/main.cpp
deleted file mode 100644
index 6ec72c3d05..0000000000
--- a/examples/qml/shell/main.cpp
+++ /dev/null
@@ -1,116 +0,0 @@
-// Copyright (C) 2017 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-
-#include <QtCore/qfile.h>
-#include <QtCore/qtextstream.h>
-#include <QtCore/qstringlist.h>
-#include <QtCore/qscopedpointer.h>
-
-#include <QtCore/QCoreApplication>
-
-#include <QtQml/qjsengine.h>
-
-#include <stdlib.h>
-
-
-class CommandInterface : public QObject
-{
- Q_OBJECT
-public:
- Q_INVOKABLE void quit() { m_wantsToQuit = true; }
- static bool wantsToQuit() { return m_wantsToQuit; }
-private:
- static bool m_wantsToQuit;
-};
-
-bool CommandInterface::m_wantsToQuit = false;
-
-
-static void interactive(QJSEngine *eng)
-{
- QTextStream qin(stdin, QFile::ReadOnly);
- const char *prompt = "qs> ";
-
- forever {
- QString line;
-
- printf("%s", prompt);
- fflush(stdout);
-
- line = qin.readLine();
- if (line.isNull())
- break;
-
- if (line.trimmed().isEmpty())
- continue;
-
- line += QLatin1Char('\n');
-
- QJSValue result = eng->evaluate(line, QLatin1String("typein"));
-
- fprintf(stderr, "%s\n", qPrintable(result.toString()));
-
- if (CommandInterface::wantsToQuit())
- break;
- }
-}
-
-int main(int argc, char *argv[])
-{
- QCoreApplication app(argc, argv);
- QScopedPointer<QJSEngine> eng(new QJSEngine());
- {
- QJSValue globalObject = eng->globalObject();
- QJSValue interface = eng->newQObject(new CommandInterface);
- globalObject.setProperty("qt", interface);
- }
-
- if (! *++argv) {
- interactive(eng.data());
- return EXIT_SUCCESS;
- }
-
- while (const char *arg = *argv++) {
- QString fileName = QString::fromLocal8Bit(arg);
-
- if (fileName == QLatin1String("-i")) {
- interactive(eng.data());
- break;
- }
-
- QString contents;
- int lineNumber = 1;
-
- if (fileName == QLatin1String("-")) {
- QTextStream stream(stdin, QFile::ReadOnly);
- contents = stream.readAll();
- } else {
- QFile file(fileName);
- if (file.open(QFile::ReadOnly)) {
- QTextStream stream(&file);
- contents = stream.readAll();
- file.close();
-
- // strip off #!/usr/bin/env qjs line
- if (contents.startsWith("#!")) {
- contents.remove(0, contents.indexOf("\n"));
- ++lineNumber;
- }
- }
- }
-
- if (contents.isEmpty())
- continue;
-
- QJSValue result = eng->evaluate(contents, fileName, lineNumber);
- if (result.isError()) {
- fprintf (stderr, " %s\n\n", qPrintable(result.toString()));
- return EXIT_FAILURE;
- }
- }
-
- return EXIT_SUCCESS;
-}
-
-#include <main.moc>
diff --git a/examples/qml/shell/shell.pro b/examples/qml/shell/shell.pro
deleted file mode 100644
index 9215108e6d..0000000000
--- a/examples/qml/shell/shell.pro
+++ /dev/null
@@ -1,9 +0,0 @@
-QT = core qml
-
-win32: CONFIG += console
-mac:CONFIG -= app_bundle
-
-SOURCES += main.cpp
-
-target.path = $$[QT_INSTALL_EXAMPLES]/qml/shell
-INSTALLS += target
diff --git a/examples/qml/tutorials/CMakeLists.txt b/examples/qml/tutorials/CMakeLists.txt
index 1a82ed75af..ecfec86a25 100644
--- a/examples/qml/tutorials/CMakeLists.txt
+++ b/examples/qml/tutorials/CMakeLists.txt
@@ -1,6 +1,6 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-if(TARGET Qt::Quick)
+if(TARGET Qt6::Quick)
add_subdirectory(extending-qml)
endif()
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..4b47f135a3
--- /dev/null
+++ b/examples/qml/tutorials/extending-qml-advanced/CMakeLists.txt
@@ -0,0 +1,12 @@
+# Copyright (C) 2023 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+if(NOT ANDROID)
+ qt_internal_add_example(advanced1-Base-project)
+ qt_internal_add_example(advanced2-Inheritance-and-coercion)
+ qt_internal_add_example(advanced3-Default-properties)
+endif(NOT ANDROID)
+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/tutorials/extending-qml-advanced/advanced1-Base-project/CMakeLists.txt b/examples/qml/tutorials/extending-qml-advanced/advanced1-Base-project/CMakeLists.txt
new file mode 100644
index 0000000000..45dfbc0b12
--- /dev/null
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced1-Base-project/CMakeLists.txt
@@ -0,0 +1,50 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+cmake_minimum_required(VERSION 3.16)
+project(baseproject LANGUAGES CXX)
+
+if (ANDROID)
+ message(FATAL_ERROR "This project cannot be built on Android.")
+endif()
+
+find_package(Qt6 REQUIRED COMPONENTS Core Qml)
+qt_standard_project_setup()
+
+qt_policy(SET QTP0001 NEW)
+
+qt_add_executable(baseproject
+ birthdayparty.cpp birthdayparty.h
+ main.cpp
+ person.cpp person.h
+)
+
+set_target_properties(baseproject PROPERTIES
+ WIN32_EXECUTABLE TRUE
+ MACOSX_BUNDLE TRUE
+)
+
+target_link_libraries(baseproject PUBLIC
+ Qt6::Core
+ Qt6::Qml
+)
+
+qt_add_qml_module(baseproject
+ URI People
+ QML_FILES Main.qml
+)
+
+install(TARGETS baseproject
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_qml_app_script(
+ TARGET baseproject
+ OUTPUT_SCRIPT deploy_script
+ MACOS_BUNDLE_POST_BUILD
+ NO_UNSUPPORTED_PLATFORM_ERROR
+ DEPLOY_USER_QML_MODULES_ON_UNSUPPORTED_PLATFORM
+)
+install(SCRIPT ${deploy_script})
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/properties/person.h b/examples/qml/tutorials/extending-qml-advanced/advanced1-Base-project/person.h
index d8d4941183..ded272626a 100644
--- a/examples/qml/referenceexamples/properties/person.h
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced1-Base-project/person.h
@@ -1,17 +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>
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;
@@ -22,6 +22,10 @@ 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/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/tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion/CMakeLists.txt b/examples/qml/tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion/CMakeLists.txt
new file mode 100644
index 0000000000..a2fa4812eb
--- /dev/null
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion/CMakeLists.txt
@@ -0,0 +1,50 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+cmake_minimum_required(VERSION 3.16)
+project(coercion LANGUAGES CXX)
+
+if (ANDROID)
+ message(FATAL_ERROR "This project cannot be built on Android.")
+endif()
+
+find_package(Qt6 REQUIRED COMPONENTS Core Qml)
+qt_standard_project_setup()
+
+qt_policy(SET QTP0001 NEW)
+
+qt_add_executable(coercion
+ birthdayparty.cpp birthdayparty.h
+ main.cpp
+ person.cpp person.h
+)
+
+set_target_properties(coercion PROPERTIES
+ WIN32_EXECUTABLE TRUE
+ MACOSX_BUNDLE TRUE
+)
+
+target_link_libraries(coercion PUBLIC
+ Qt6::Core
+ Qt6::Qml
+)
+
+qt_add_qml_module(coercion
+ URI People
+ QML_FILES Main.qml
+)
+
+install(TARGETS coercion
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_qml_app_script(
+ TARGET coercion
+ OUTPUT_SCRIPT deploy_script
+ MACOS_BUNDLE_POST_BUILD
+ NO_UNSUPPORTED_PLATFORM_ERROR
+ DEPLOY_USER_QML_MODULES_ON_UNSUPPORTED_PLATFORM
+)
+install(SCRIPT ${deploy_script})
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/tutorials/extending-qml-advanced/advanced3-Default-properties/CMakeLists.txt b/examples/qml/tutorials/extending-qml-advanced/advanced3-Default-properties/CMakeLists.txt
new file mode 100644
index 0000000000..0682e487c8
--- /dev/null
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced3-Default-properties/CMakeLists.txt
@@ -0,0 +1,50 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+cmake_minimum_required(VERSION 3.16)
+project(default LANGUAGES CXX)
+
+if (ANDROID)
+ message(FATAL_ERROR "This project cannot be built on Android.")
+endif()
+
+find_package(Qt6 REQUIRED COMPONENTS Core Qml)
+qt_standard_project_setup()
+
+qt_policy(SET QTP0001 NEW)
+
+qt_add_executable(default
+ birthdayparty.cpp birthdayparty.h
+ main.cpp
+ person.cpp person.h
+)
+
+set_target_properties(default PROPERTIES
+ WIN32_EXECUTABLE TRUE
+ MACOSX_BUNDLE TRUE
+)
+
+target_link_libraries(default PUBLIC
+ Qt6::Core
+ Qt6::Qml
+)
+
+qt_add_qml_module(default
+ URI People
+ QML_FILES Main.qml
+)
+
+install(TARGETS default
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_qml_app_script(
+ TARGET default
+ OUTPUT_SCRIPT deploy_script
+ MACOS_BUNDLE_POST_BUILD
+ NO_UNSUPPORTED_PLATFORM_ERROR
+ DEPLOY_USER_QML_MODULES_ON_UNSUPPORTED_PLATFORM
+)
+install(SCRIPT ${deploy_script})
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/tutorials/extending-qml-advanced/advanced4-Grouped-properties/CMakeLists.txt b/examples/qml/tutorials/extending-qml-advanced/advanced4-Grouped-properties/CMakeLists.txt
new file mode 100644
index 0000000000..8f66d1ad07
--- /dev/null
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced4-Grouped-properties/CMakeLists.txt
@@ -0,0 +1,49 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+cmake_minimum_required(VERSION 3.16)
+project(grouped LANGUAGES CXX)
+
+find_package(Qt6 REQUIRED COMPONENTS Core Qml Gui)
+qt_standard_project_setup()
+
+qt_policy(SET QTP0001 NEW)
+
+qt_add_executable(grouped
+ birthdayparty.cpp birthdayparty.h
+ main.cpp
+ person.cpp person.h
+)
+
+set_target_properties(grouped PROPERTIES
+ WIN32_EXECUTABLE TRUE
+ MACOSX_BUNDLE TRUE
+)
+
+target_link_libraries(grouped PUBLIC
+ Qt6::Core
+ Qt6::Qml
+ Qt6::Gui
+)
+
+qt_add_qml_module(grouped
+ URI People
+ QML_FILES Main.qml
+ DEPENDENCIES
+ QtQuick
+)
+
+install(TARGETS grouped
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_qml_app_script(
+ TARGET grouped
+ OUTPUT_SCRIPT deploy_script
+ MACOS_BUNDLE_POST_BUILD
+ NO_UNSUPPORTED_PLATFORM_ERROR
+ DEPLOY_USER_QML_MODULES_ON_UNSUPPORTED_PLATFORM
+)
+install(SCRIPT ${deploy_script})
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..53cec6b192
--- /dev/null
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced4-Grouped-properties/person.cpp
@@ -0,0 +1,96 @@
+// 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();
+ }
+}
+
+bool ShoeDescription::operatorEqualsImpl(const ShoeDescription &lhs, const ShoeDescription &rhs)
+{
+ return lhs.m_size == rhs.m_size && lhs.m_color == rhs.m_color && lhs.m_brand == rhs.m_brand
+ && lhs.m_price == rhs.m_price;
+}
+
+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 (!shoe)
+ return;
+
+ 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..4f040e491b 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;
@@ -31,10 +31,21 @@ public:
qreal price() const;
void setPrice(qreal);
+ friend bool operator==(const ShoeDescription &lhs, const ShoeDescription &rhs)
+ {
+ return operatorEqualsImpl(lhs, rhs);
+ }
+ friend bool operator!=(const ShoeDescription &lhs, const ShoeDescription &rhs)
+ {
+ return !operatorEqualsImpl(lhs, rhs);
+ }
+
signals:
void shoeChanged();
private:
+ static bool operatorEqualsImpl(const ShoeDescription &, const ShoeDescription &);
+
int m_size = 0;
QColor m_color;
QString m_brand;
@@ -44,25 +55,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/tutorials/extending-qml-advanced/advanced5-Attached-properties/CMakeLists.txt b/examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties/CMakeLists.txt
new file mode 100644
index 0000000000..c7b30376b6
--- /dev/null
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties/CMakeLists.txt
@@ -0,0 +1,49 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+cmake_minimum_required(VERSION 3.16)
+project(attached LANGUAGES CXX)
+
+find_package(Qt6 REQUIRED COMPONENTS Core Qml Quick)
+qt_standard_project_setup()
+
+qt_policy(SET QTP0001 NEW)
+
+qt_add_executable(attached
+ birthdayparty.cpp birthdayparty.h
+ main.cpp
+ person.cpp person.h
+)
+
+set_target_properties(attached PROPERTIES
+ WIN32_EXECUTABLE TRUE
+ MACOSX_BUNDLE TRUE
+)
+
+target_link_libraries(attached PUBLIC
+ Qt6::Core
+ Qt6::Qml
+ Qt6::Quick
+)
+
+qt_add_qml_module(attached
+ URI People
+ QML_FILES Main.qml
+ DEPENDENCIES
+ QtQuick
+)
+
+install(TARGETS attached
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_qml_app_script(
+ TARGET attached
+ OUTPUT_SCRIPT deploy_script
+ MACOS_BUNDLE_POST_BUILD
+ NO_UNSUPPORTED_PLATFORM_ERROR
+ DEPLOY_USER_QML_MODULES_ON_UNSUPPORTED_PLATFORM
+)
+install(SCRIPT ${deploy_script})
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..53cec6b192
--- /dev/null
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties/person.cpp
@@ -0,0 +1,96 @@
+// 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();
+ }
+}
+
+bool ShoeDescription::operatorEqualsImpl(const ShoeDescription &lhs, const ShoeDescription &rhs)
+{
+ return lhs.m_size == rhs.m_size && lhs.m_color == rhs.m_color && lhs.m_brand == rhs.m_brand
+ && lhs.m_price == rhs.m_price;
+}
+
+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 (!shoe)
+ return;
+
+ if (*m_shoe != *shoe) {
+ m_shoe = shoe;
+ emit shoeChanged();
+ }
+}
diff --git a/examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties/person.h b/examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties/person.h
new file mode 100644
index 0000000000..4f040e491b
--- /dev/null
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties/person.h
@@ -0,0 +1,98 @@
+// 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 <QColor>
+#include <QObject>
+
+class ShoeDescription : public QObject
+{
+ Q_OBJECT
+ 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;
+
+ 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);
+
+ friend bool operator==(const ShoeDescription &lhs, const ShoeDescription &rhs)
+ {
+ return operatorEqualsImpl(lhs, rhs);
+ }
+ friend bool operator!=(const ShoeDescription &lhs, const ShoeDescription &rhs)
+ {
+ return !operatorEqualsImpl(lhs, rhs);
+ }
+
+signals:
+ void shoeChanged();
+
+private:
+ static bool operatorEqualsImpl(const ShoeDescription &, const ShoeDescription &);
+
+ 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 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() const;
+ void setShoe(ShoeDescription *shoe);
+
+signals:
+ void nameChanged();
+ void shoeChanged();
+
+private:
+ QString m_name;
+ ShoeDescription *m_shoe = nullptr;
+};
+
+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/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/tutorials/extending-qml-advanced/advanced6-Property-value-source/CMakeLists.txt b/examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/CMakeLists.txt
new file mode 100644
index 0000000000..e6aa49e5cb
--- /dev/null
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/CMakeLists.txt
@@ -0,0 +1,50 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+cmake_minimum_required(VERSION 3.16)
+project(valuesource LANGUAGES CXX)
+
+find_package(Qt6 REQUIRED COMPONENTS Core Qml Quick)
+qt_standard_project_setup()
+
+qt_policy(SET QTP0001 NEW)
+
+qt_add_executable(valuesource
+ birthdayparty.cpp birthdayparty.h
+ happybirthdaysong.cpp happybirthdaysong.h
+ main.cpp
+ person.cpp person.h
+)
+
+set_target_properties(valuesource PROPERTIES
+ WIN32_EXECUTABLE TRUE
+ MACOSX_BUNDLE TRUE
+)
+
+target_link_libraries(valuesource PUBLIC
+ Qt6::Core
+ Qt6::Qml
+ Qt6::Quick
+)
+
+qt_add_qml_module(valuesource
+ URI People
+ QML_FILES Main.qml
+ DEPENDENCIES
+ QtQuick
+)
+
+install(TARGETS valuesource
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_qml_app_script(
+ TARGET valuesource
+ OUTPUT_SCRIPT deploy_script
+ MACOS_BUNDLE_POST_BUILD
+ NO_UNSUPPORTED_PLATFORM_ERROR
+ DEPLOY_USER_QML_MODULES_ON_UNSUPPORTED_PLATFORM
+)
+install(SCRIPT ${deploy_script})
diff --git a/examples/qml/referenceexamples/binding/example.qml b/examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/Main.qml
index 262d667903..7f79d0a0c4 100644
--- a/examples/qml/referenceexamples/binding/example.qml
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/Main.qml
@@ -1,26 +1,26 @@
-// 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
+ }
+
+ 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 +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/valuesource/happybirthdaysong.cpp b/examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/happybirthdaysong.cpp
index e9a8c13ae9..7a756a4a71 100644
--- a/examples/qml/referenceexamples/valuesource/happybirthdaysong.cpp
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/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/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..53cec6b192
--- /dev/null
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/person.cpp
@@ -0,0 +1,96 @@
+// 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();
+ }
+}
+
+bool ShoeDescription::operatorEqualsImpl(const ShoeDescription &lhs, const ShoeDescription &rhs)
+{
+ return lhs.m_size == rhs.m_size && lhs.m_color == rhs.m_color && lhs.m_brand == rhs.m_brand
+ && lhs.m_price == rhs.m_price;
+}
+
+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 (!shoe)
+ return;
+
+ if (*m_shoe != *shoe) {
+ m_shoe = shoe;
+ emit shoeChanged();
+ }
+}
diff --git a/examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/person.h b/examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/person.h
new file mode 100644
index 0000000000..4f040e491b
--- /dev/null
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/person.h
@@ -0,0 +1,98 @@
+// 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 <QColor>
+#include <QObject>
+
+class ShoeDescription : public QObject
+{
+ Q_OBJECT
+ 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;
+
+ 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);
+
+ friend bool operator==(const ShoeDescription &lhs, const ShoeDescription &rhs)
+ {
+ return operatorEqualsImpl(lhs, rhs);
+ }
+ friend bool operator!=(const ShoeDescription &lhs, const ShoeDescription &rhs)
+ {
+ return !operatorEqualsImpl(lhs, rhs);
+ }
+
+signals:
+ void shoeChanged();
+
+private:
+ static bool operatorEqualsImpl(const ShoeDescription &, const ShoeDescription &);
+
+ 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 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() const;
+ void setShoe(ShoeDescription *shoe);
+
+signals:
+ void nameChanged();
+ void shoeChanged();
+
+private:
+ QString m_name;
+ ShoeDescription *m_shoe = nullptr;
+};
+
+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/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..ffdb5b0949
--- /dev/null
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/CMakeLists.txt
@@ -0,0 +1,63 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+cmake_minimum_required(VERSION 3.16)
+project(foreign LANGUAGES CXX)
+
+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
+ Qt6::Core
+ Qt6::Qml
+ Qt6::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
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_qml_app_script(
+ TARGET foreign
+ OUTPUT_SCRIPT deploy_script
+ MACOS_BUNDLE_POST_BUILD
+ NO_UNSUPPORTED_PLATFORM_ERROR
+ DEPLOY_USER_QML_MODULES_ON_UNSUPPORTED_PLATFORM
+)
+install(SCRIPT ${deploy_script})
diff --git a/examples/qml/referenceexamples/valuesource/example.qml b/examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/Main.qml
index b6efe211c1..988bea49f8 100644
--- a/examples/qml/referenceexamples/valuesource/example.qml
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/Main.qml
@@ -1,13 +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
import People
import QtQuick // For QColor
-// ![0]
BirthdayParty {
- HappyBirthdaySong on announcement { name: "Bob Jones" }
-// ![0]
+ 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); }
@@ -19,7 +25,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 +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/binding/happybirthdaysong.cpp b/examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/happybirthdaysong.cpp
index cf71a7f213..7a756a4a71 100644
--- a/examples/qml/referenceexamples/binding/happybirthdaysong.cpp
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/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/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..7fa6d6a81a
--- /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: LicenseRef-Qt-Commercial OR 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
+ Qt6::Core
+ Qt6::Qml
+ Qt6::Quick
+ Qt6::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..53cec6b192
--- /dev/null
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/person.cpp
@@ -0,0 +1,96 @@
+// 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();
+ }
+}
+
+bool ShoeDescription::operatorEqualsImpl(const ShoeDescription &lhs, const ShoeDescription &rhs)
+{
+ return lhs.m_size == rhs.m_size && lhs.m_color == rhs.m_color && lhs.m_brand == rhs.m_brand
+ && lhs.m_price == rhs.m_price;
+}
+
+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 (!shoe)
+ return;
+
+ if (*m_shoe != *shoe) {
+ m_shoe = shoe;
+ emit shoeChanged();
+ }
+}
diff --git a/examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/person.h b/examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/person.h
new file mode 100644
index 0000000000..03c2dab953
--- /dev/null
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced7-Foreign-objects-integration/person.h
@@ -0,0 +1,98 @@
+// 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>
+
+class ShoeDescription : public QObject
+{
+ Q_OBJECT
+ 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;
+
+ 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);
+
+ friend bool operator==(const ShoeDescription &lhs, const ShoeDescription &rhs)
+ {
+ return operatorEqualsImpl(lhs, rhs);
+ }
+ friend bool operator!=(const ShoeDescription &lhs, const ShoeDescription &rhs)
+ {
+ return !operatorEqualsImpl(lhs, rhs);
+ }
+
+signals:
+ void shoeChanged();
+
+private:
+ static bool operatorEqualsImpl(const ShoeDescription &, const ShoeDescription &);
+
+ 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 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() const;
+ void setShoe(ShoeDescription *shoe);
+
+signals:
+ void nameChanged();
+ void shoeChanged();
+
+private:
+ QString m_name;
+ ShoeDescription *m_shoe = nullptr;
+};
+
+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/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/examples/qml/tutorials/extending-qml/CMakeLists.txt b/examples/qml/tutorials/extending-qml/CMakeLists.txt
index f5fc6e5cfe..87e3eaf54d 100644
--- a/examples/qml/tutorials/extending-qml/CMakeLists.txt
+++ b/examples/qml/tutorials/extending-qml/CMakeLists.txt
@@ -1,5 +1,5 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
qt_internal_add_example(chapter1-basics)
qt_internal_add_example(chapter2-methods)
diff --git a/examples/qml/tutorials/extending-qml/chapter1-basics/app.qml b/examples/qml/tutorials/extending-qml/chapter1-basics/App.qml
index ed89ce97c4..ed89ce97c4 100644
--- a/examples/qml/tutorials/extending-qml/chapter1-basics/app.qml
+++ b/examples/qml/tutorials/extending-qml/chapter1-basics/App.qml
diff --git a/examples/qml/tutorials/extending-qml/chapter1-basics/CMakeLists.txt b/examples/qml/tutorials/extending-qml/chapter1-basics/CMakeLists.txt
index 02ed972ef5..0080197766 100644
--- a/examples/qml/tutorials/extending-qml/chapter1-basics/CMakeLists.txt
+++ b/examples/qml/tutorials/extending-qml/chapter1-basics/CMakeLists.txt
@@ -1,19 +1,13 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(chapter1-basics LANGUAGES CXX)
-set(CMAKE_AUTOMOC ON)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/qml/tutorials/extending-qml/chapter1-basics")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Qml Quick)
+qt_standard_project_setup(REQUIRES 6.5)
+
qt_add_executable(chapter1-basics
main.cpp
piechart.cpp piechart.h
@@ -25,21 +19,29 @@ set_target_properties(chapter1-basics PROPERTIES
)
target_link_libraries(chapter1-basics PUBLIC
- Qt::Core
- Qt::Gui
- Qt::Qml
- Qt::Quick
+ Qt6::Core
+ Qt6::Gui
+ Qt6::Qml
+ Qt6::Quick
)
#![0]
qt_add_qml_module(chapter1-basics
URI Charts
- QML_FILES app.qml
- NO_RESOURCE_TARGET_PATH
+ QML_FILES App.qml
DEPENDENCIES QtQuick
)
#![0]
install(TARGETS chapter1-basics
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_qml_app_script(
+ TARGET chapter1-basics
+ OUTPUT_SCRIPT deploy_script
+ MACOS_BUNDLE_POST_BUILD
+ NO_UNSUPPORTED_PLATFORM_ERROR
+ DEPLOY_USER_QML_MODULES_ON_UNSUPPORTED_PLATFORM
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/qml/tutorials/extending-qml/chapter1-basics/chapter1-basics.qrc b/examples/qml/tutorials/extending-qml/chapter1-basics/chapter1-basics.qrc
index f1168aef3b..c72f203e67 100644
--- a/examples/qml/tutorials/extending-qml/chapter1-basics/chapter1-basics.qrc
+++ b/examples/qml/tutorials/extending-qml/chapter1-basics/chapter1-basics.qrc
@@ -1,5 +1,6 @@
<RCC>
- <qresource prefix="/">
- <file>app.qml</file>
+ <qresource prefix="/qt/qml/Charts">
+ <file>App.qml</file>
+ <file>qmldir</file>
</qresource>
</RCC>
diff --git a/examples/qml/tutorials/extending-qml/chapter1-basics/main.cpp b/examples/qml/tutorials/extending-qml/chapter1-basics/main.cpp
index f2eaab03bc..bc4bbba809 100644
--- a/examples/qml/tutorials/extending-qml/chapter1-basics/main.cpp
+++ b/examples/qml/tutorials/extending-qml/chapter1-basics/main.cpp
@@ -11,7 +11,7 @@ int main(int argc, char *argv[])
QQuickView view;
view.setResizeMode(QQuickView::SizeRootObjectToView);
- view.setSource(QUrl("qrc:///app.qml"));
+ view.loadFromModule("Charts", "App");
view.show();
return QGuiApplication::exec();
}
diff --git a/examples/qml/tutorials/extending-qml/chapter1-basics/qmldir b/examples/qml/tutorials/extending-qml/chapter1-basics/qmldir
new file mode 100644
index 0000000000..f69878a753
--- /dev/null
+++ b/examples/qml/tutorials/extending-qml/chapter1-basics/qmldir
@@ -0,0 +1,6 @@
+module Charts
+typeinfo chapter1-basics.qmltypes
+depends QtQuick
+prefer :/qt/qml/Charts/
+App 254.0 App.qml
+
diff --git a/examples/qml/tutorials/extending-qml/chapter2-methods/app.qml b/examples/qml/tutorials/extending-qml/chapter2-methods/App.qml
index 56597c3f42..56597c3f42 100644
--- a/examples/qml/tutorials/extending-qml/chapter2-methods/app.qml
+++ b/examples/qml/tutorials/extending-qml/chapter2-methods/App.qml
diff --git a/examples/qml/tutorials/extending-qml/chapter2-methods/CMakeLists.txt b/examples/qml/tutorials/extending-qml/chapter2-methods/CMakeLists.txt
index f0906cf380..3fc7d3ffbf 100644
--- a/examples/qml/tutorials/extending-qml/chapter2-methods/CMakeLists.txt
+++ b/examples/qml/tutorials/extending-qml/chapter2-methods/CMakeLists.txt
@@ -1,19 +1,13 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(chapter2-methods LANGUAGES CXX)
-set(CMAKE_AUTOMOC ON)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/qml/tutorials/extending-qml/chapter2-methods")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Qml Quick)
+qt_standard_project_setup(REQUIRES 6.5)
+
qt_add_executable(chapter2-methods
main.cpp
piechart.cpp piechart.h
@@ -25,21 +19,29 @@ set_target_properties(chapter2-methods PROPERTIES
)
target_link_libraries(chapter2-methods PUBLIC
- Qt::Core
- Qt::Gui
- Qt::Qml
- Qt::Quick
+ Qt6::Core
+ Qt6::Gui
+ Qt6::Qml
+ Qt6::Quick
)
qt_add_qml_module(chapter2-methods
URI Charts
- QML_FILES app.qml
- NO_RESOURCE_TARGET_PATH
+ QML_FILES App.qml
DEPENDENCIES QtQuick
)
install(TARGETS chapter2-methods
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_qml_app_script(
+ TARGET chapter2-methods
+ OUTPUT_SCRIPT deploy_script
+ MACOS_BUNDLE_POST_BUILD
+ NO_UNSUPPORTED_PLATFORM_ERROR
+ DEPLOY_USER_QML_MODULES_ON_UNSUPPORTED_PLATFORM
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/qml/tutorials/extending-qml/chapter2-methods/chapter2-methods.qrc b/examples/qml/tutorials/extending-qml/chapter2-methods/chapter2-methods.qrc
index f1168aef3b..c72f203e67 100644
--- a/examples/qml/tutorials/extending-qml/chapter2-methods/chapter2-methods.qrc
+++ b/examples/qml/tutorials/extending-qml/chapter2-methods/chapter2-methods.qrc
@@ -1,5 +1,6 @@
<RCC>
- <qresource prefix="/">
- <file>app.qml</file>
+ <qresource prefix="/qt/qml/Charts">
+ <file>App.qml</file>
+ <file>qmldir</file>
</qresource>
</RCC>
diff --git a/examples/qml/tutorials/extending-qml/chapter2-methods/main.cpp b/examples/qml/tutorials/extending-qml/chapter2-methods/main.cpp
index f2eaab03bc..bc4bbba809 100644
--- a/examples/qml/tutorials/extending-qml/chapter2-methods/main.cpp
+++ b/examples/qml/tutorials/extending-qml/chapter2-methods/main.cpp
@@ -11,7 +11,7 @@ int main(int argc, char *argv[])
QQuickView view;
view.setResizeMode(QQuickView::SizeRootObjectToView);
- view.setSource(QUrl("qrc:///app.qml"));
+ view.loadFromModule("Charts", "App");
view.show();
return QGuiApplication::exec();
}
diff --git a/examples/qml/tutorials/extending-qml/chapter2-methods/qmldir b/examples/qml/tutorials/extending-qml/chapter2-methods/qmldir
new file mode 100644
index 0000000000..e8b0c98311
--- /dev/null
+++ b/examples/qml/tutorials/extending-qml/chapter2-methods/qmldir
@@ -0,0 +1,6 @@
+module Charts
+typeinfo chapter2-methods.qmltypes
+depends QtQuick
+prefer :/qt/qml/Charts/
+App 254.0 App.qml
+
diff --git a/examples/qml/tutorials/extending-qml/chapter3-bindings/app.qml b/examples/qml/tutorials/extending-qml/chapter3-bindings/App.qml
index d29eaf4b9f..d29eaf4b9f 100644
--- a/examples/qml/tutorials/extending-qml/chapter3-bindings/app.qml
+++ b/examples/qml/tutorials/extending-qml/chapter3-bindings/App.qml
diff --git a/examples/qml/tutorials/extending-qml/chapter3-bindings/CMakeLists.txt b/examples/qml/tutorials/extending-qml/chapter3-bindings/CMakeLists.txt
index 05c567fd30..a842eb48ca 100644
--- a/examples/qml/tutorials/extending-qml/chapter3-bindings/CMakeLists.txt
+++ b/examples/qml/tutorials/extending-qml/chapter3-bindings/CMakeLists.txt
@@ -1,19 +1,13 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(chapter3-bindings LANGUAGES CXX)
-set(CMAKE_AUTOMOC ON)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/qml/tutorials/extending-qml/chapter3-bindings")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Qml Quick)
+qt_standard_project_setup(REQUIRES 6.5)
+
qt_add_executable(chapter3-bindings
main.cpp
piechart.cpp piechart.h
@@ -25,21 +19,29 @@ set_target_properties(chapter3-bindings PROPERTIES
)
target_link_libraries(chapter3-bindings PUBLIC
- Qt::Core
- Qt::Gui
- Qt::Qml
- Qt::Quick
+ Qt6::Core
+ Qt6::Gui
+ Qt6::Qml
+ Qt6::Quick
)
qt_add_qml_module(chapter3-bindings
URI Charts
- QML_FILES app.qml
- NO_RESOURCE_TARGET_PATH
+ QML_FILES App.qml
DEPENDENCIES QtQuick
)
install(TARGETS chapter3-bindings
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_qml_app_script(
+ TARGET chapter3-bindings
+ OUTPUT_SCRIPT deploy_script
+ MACOS_BUNDLE_POST_BUILD
+ NO_UNSUPPORTED_PLATFORM_ERROR
+ DEPLOY_USER_QML_MODULES_ON_UNSUPPORTED_PLATFORM
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/qml/tutorials/extending-qml/chapter3-bindings/chapter3-bindings.qrc b/examples/qml/tutorials/extending-qml/chapter3-bindings/chapter3-bindings.qrc
index f1168aef3b..c72f203e67 100644
--- a/examples/qml/tutorials/extending-qml/chapter3-bindings/chapter3-bindings.qrc
+++ b/examples/qml/tutorials/extending-qml/chapter3-bindings/chapter3-bindings.qrc
@@ -1,5 +1,6 @@
<RCC>
- <qresource prefix="/">
- <file>app.qml</file>
+ <qresource prefix="/qt/qml/Charts">
+ <file>App.qml</file>
+ <file>qmldir</file>
</qresource>
</RCC>
diff --git a/examples/qml/tutorials/extending-qml/chapter3-bindings/main.cpp b/examples/qml/tutorials/extending-qml/chapter3-bindings/main.cpp
index f2eaab03bc..bc4bbba809 100644
--- a/examples/qml/tutorials/extending-qml/chapter3-bindings/main.cpp
+++ b/examples/qml/tutorials/extending-qml/chapter3-bindings/main.cpp
@@ -11,7 +11,7 @@ int main(int argc, char *argv[])
QQuickView view;
view.setResizeMode(QQuickView::SizeRootObjectToView);
- view.setSource(QUrl("qrc:///app.qml"));
+ view.loadFromModule("Charts", "App");
view.show();
return QGuiApplication::exec();
}
diff --git a/examples/qml/tutorials/extending-qml/chapter3-bindings/qmldir b/examples/qml/tutorials/extending-qml/chapter3-bindings/qmldir
new file mode 100644
index 0000000000..f0911d3c89
--- /dev/null
+++ b/examples/qml/tutorials/extending-qml/chapter3-bindings/qmldir
@@ -0,0 +1,6 @@
+module Charts
+typeinfo chapter3-bindings.qmltypes
+depends QtQuick
+prefer :/qt/qml/Charts/
+App 254.0 App.qml
+
diff --git a/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/app.qml b/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/App.qml
index 2edcda568e..2edcda568e 100644
--- a/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/app.qml
+++ b/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/App.qml
diff --git a/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/CMakeLists.txt b/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/CMakeLists.txt
index 3914819640..fd6428093b 100644
--- a/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/CMakeLists.txt
+++ b/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/CMakeLists.txt
@@ -1,18 +1,13 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(chapter4-customPropertyTypes LANGUAGES CXX)
-set(CMAKE_AUTOMOC ON)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
+find_package(Qt6 REQUIRED COMPONENTS Core Gui Qml Quick)
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/qml/tutorials/extending-qml/chapter4-customPropertyTypes")
+qt_standard_project_setup(REQUIRES 6.5)
-find_package(Qt6 REQUIRED COMPONENTS Core Gui Qml Quick)
#![0]
qt_add_executable(chapter4-customPropertyTypes
main.cpp
@@ -26,21 +21,29 @@ set_target_properties(chapter4-customPropertyTypes PROPERTIES
)
target_link_libraries(chapter4-customPropertyTypes PUBLIC
- Qt::Core
- Qt::Gui
- Qt::Qml
- Qt::Quick
+ Qt6::Core
+ Qt6::Gui
+ Qt6::Qml
+ Qt6::Quick
)
#![1]
qt_add_qml_module(chapter4-customPropertyTypes
URI Charts
- QML_FILES app.qml
- NO_RESOURCE_TARGET_PATH
+ QML_FILES App.qml
DEPENDENCIES QtQuick
)
#![1]
install(TARGETS chapter4-customPropertyTypes
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_qml_app_script(
+ TARGET chapter4-customPropertyTypes
+ OUTPUT_SCRIPT deploy_script
+ MACOS_BUNDLE_POST_BUILD
+ NO_UNSUPPORTED_PLATFORM_ERROR
+ DEPLOY_USER_QML_MODULES_ON_UNSUPPORTED_PLATFORM
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/chapter4-customPropertyTypes.qrc b/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/chapter4-customPropertyTypes.qrc
index f1168aef3b..c72f203e67 100644
--- a/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/chapter4-customPropertyTypes.qrc
+++ b/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/chapter4-customPropertyTypes.qrc
@@ -1,5 +1,6 @@
<RCC>
- <qresource prefix="/">
- <file>app.qml</file>
+ <qresource prefix="/qt/qml/Charts">
+ <file>App.qml</file>
+ <file>qmldir</file>
</qresource>
</RCC>
diff --git a/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/main.cpp b/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/main.cpp
index 8833750ebf..09a025ae85 100644
--- a/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/main.cpp
+++ b/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/main.cpp
@@ -14,7 +14,7 @@ int main(int argc, char *argv[])
QQuickView view;
view.setResizeMode(QQuickView::SizeRootObjectToView);
- view.setSource(QUrl("qrc:///app.qml"));
+ view.loadFromModule("Charts", "App");
view.show();
return QGuiApplication::exec();
diff --git a/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/qmldir b/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/qmldir
new file mode 100644
index 0000000000..14c64f5269
--- /dev/null
+++ b/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/qmldir
@@ -0,0 +1,6 @@
+module Charts
+typeinfo chapter4-customPropertyTypes.qmltypes
+depends QtQuick
+prefer :/qt/qml/Charts/
+App 254.0 App.qml
+
diff --git a/examples/qml/tutorials/extending-qml/chapter5-listproperties/app.qml b/examples/qml/tutorials/extending-qml/chapter5-listproperties/App.qml
index 9e200a9b60..9e200a9b60 100644
--- a/examples/qml/tutorials/extending-qml/chapter5-listproperties/app.qml
+++ b/examples/qml/tutorials/extending-qml/chapter5-listproperties/App.qml
diff --git a/examples/qml/tutorials/extending-qml/chapter5-listproperties/CMakeLists.txt b/examples/qml/tutorials/extending-qml/chapter5-listproperties/CMakeLists.txt
index d3b70f2017..73984849c0 100644
--- a/examples/qml/tutorials/extending-qml/chapter5-listproperties/CMakeLists.txt
+++ b/examples/qml/tutorials/extending-qml/chapter5-listproperties/CMakeLists.txt
@@ -1,19 +1,13 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(chapter5-listproperties LANGUAGES CXX)
-set(CMAKE_AUTOMOC ON)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/qml/tutorials/extending-qml/chapter5-listproperties")
-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Qml Quick)
+qt_standard_project_setup(REQUIRES 6.5)
+
qt_add_executable(chapter5-listproperties
main.cpp
piechart.cpp piechart.h
@@ -26,21 +20,29 @@ set_target_properties(chapter5-listproperties PROPERTIES
)
target_link_libraries(chapter5-listproperties PUBLIC
- Qt::Core
- Qt::Gui
- Qt::Qml
- Qt::Quick
+ Qt6::Core
+ Qt6::Gui
+ Qt6::Qml
+ Qt6::Quick
)
qt_add_qml_module(chapter5-listproperties
URI Charts
- QML_FILES app.qml
- NO_RESOURCE_TARGET_PATH
+ QML_FILES App.qml
DEPENDENCIES QtQuick
)
install(TARGETS chapter5-listproperties
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+qt_generate_deploy_qml_app_script(
+ TARGET chapter5-listproperties
+ OUTPUT_SCRIPT deploy_script
+ MACOS_BUNDLE_POST_BUILD
+ NO_UNSUPPORTED_PLATFORM_ERROR
+ DEPLOY_USER_QML_MODULES_ON_UNSUPPORTED_PLATFORM
)
+install(SCRIPT ${deploy_script})
diff --git a/examples/qml/tutorials/extending-qml/chapter5-listproperties/chapter5-listproperties.qrc b/examples/qml/tutorials/extending-qml/chapter5-listproperties/chapter5-listproperties.qrc
index f1168aef3b..c72f203e67 100644
--- a/examples/qml/tutorials/extending-qml/chapter5-listproperties/chapter5-listproperties.qrc
+++ b/examples/qml/tutorials/extending-qml/chapter5-listproperties/chapter5-listproperties.qrc
@@ -1,5 +1,6 @@
<RCC>
- <qresource prefix="/">
- <file>app.qml</file>
+ <qresource prefix="/qt/qml/Charts">
+ <file>App.qml</file>
+ <file>qmldir</file>
</qresource>
</RCC>
diff --git a/examples/qml/tutorials/extending-qml/chapter5-listproperties/main.cpp b/examples/qml/tutorials/extending-qml/chapter5-listproperties/main.cpp
index 3d11a689a6..12d4d49438 100644
--- a/examples/qml/tutorials/extending-qml/chapter5-listproperties/main.cpp
+++ b/examples/qml/tutorials/extending-qml/chapter5-listproperties/main.cpp
@@ -12,7 +12,7 @@ int main(int argc, char *argv[])
QQuickView view;
view.setResizeMode(QQuickView::SizeRootObjectToView);
- view.setSource(QUrl("qrc:///app.qml"));
+ view.loadFromModule("Charts", "App");
view.show();
return QGuiApplication::exec();
}
diff --git a/examples/qml/tutorials/extending-qml/chapter5-listproperties/qmldir b/examples/qml/tutorials/extending-qml/chapter5-listproperties/qmldir
new file mode 100644
index 0000000000..cebd0320ab
--- /dev/null
+++ b/examples/qml/tutorials/extending-qml/chapter5-listproperties/qmldir
@@ -0,0 +1,6 @@
+module Charts
+typeinfo chapter5-listproperties.qmltypes
+depends QtQuick
+prefer :/qt/qml/Charts/
+App 254.0 App.qml
+
diff --git a/examples/qml/tutorials/extending-qml/chapter6-plugins/app.qml b/examples/qml/tutorials/extending-qml/chapter6-plugins/App.qml
index 1d1cb74176..1d1cb74176 100644
--- a/examples/qml/tutorials/extending-qml/chapter6-plugins/app.qml
+++ b/examples/qml/tutorials/extending-qml/chapter6-plugins/App.qml
diff --git a/examples/qml/tutorials/extending-qml/chapter6-plugins/CMakeLists.txt b/examples/qml/tutorials/extending-qml/chapter6-plugins/CMakeLists.txt
index f1a7ef1b51..bd88766e0c 100644
--- a/examples/qml/tutorials/extending-qml/chapter6-plugins/CMakeLists.txt
+++ b/examples/qml/tutorials/extending-qml/chapter6-plugins/CMakeLists.txt
@@ -1,19 +1,13 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(chapter6-plugins LANGUAGES CXX)
-set(CMAKE_AUTOMOC ON)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/qml/tutorials/extending-qml/chapter6-plugins")
-
find_package(Qt6 REQUIRED COMPONENTS Qml Quick)
+qt_standard_project_setup(REQUIRES 6.5)
+
qt_add_executable(chapter6-plugins
main.cpp
)
@@ -24,20 +18,29 @@ set_target_properties(chapter6-plugins PROPERTIES
)
target_link_libraries(chapter6-plugins PRIVATE
- Qt::Qml
- Qt::Quick
+ Qt6::Qml
+ Qt6::Quick
)
qt_add_qml_module(chapter6-plugins
URI ChartsApp
- QML_FILES app.qml
- NO_RESOURCE_TARGET_PATH
+ QML_FILES App.qml
)
+add_subdirectory(Charts)
+
install(TARGETS chapter6-plugins
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
-add_subdirectory(Charts)
+qt_generate_deploy_qml_app_script(
+ TARGET chapter6-plugins
+ OUTPUT_SCRIPT deploy_script
+ MACOS_BUNDLE_POST_BUILD
+ NO_UNSUPPORTED_PLATFORM_ERROR
+ DEPLOY_USER_QML_MODULES_ON_UNSUPPORTED_PLATFORM
+)
+install(SCRIPT ${deploy_script})
+
diff --git a/examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/CMakeLists.txt b/examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/CMakeLists.txt
index 4a8f2e0b7b..a0fed166e0 100644
--- a/examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/CMakeLists.txt
+++ b/examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/CMakeLists.txt
@@ -1,5 +1,5 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
qt6_policy(SET QTP0001 NEW)
qt6_add_qml_module(chartsplugin
@@ -14,40 +14,16 @@ target_sources(chartsplugin PRIVATE
)
target_link_libraries(chartsplugin PRIVATE
- Qt::Core
- Qt::Gui
- Qt::Qml
- Qt::Quick
+ Qt6::Core
+ Qt6::Gui
+ Qt6::Qml
+ Qt6::Quick
)
-if(QT6_IS_SHARED_LIBS_BUILD AND APPLE)
- get_target_property(is_bundle chapter6-plugins MACOSX_BUNDLE)
- if(is_bundle)
- # The application's main.cpp adds an explicit QML import path to look for qml modules under
- # a PlugIns subdirectory in a macOS bundle.
- # Copy the qmldir and shared library qml plugin.
-
- set(charts_dir "$<TARGET_FILE_DIR:chartsplugin>")
- set(chars_qmldir_file "${charts_dir}/qmldir")
- set(app_dir "$<TARGET_FILE_DIR:chapter6-plugins>")
- set(bundle_charts_dir "${app_dir}/../PlugIns/Charts")
-
- add_custom_command(TARGET chartsplugin POST_BUILD
- COMMAND ${CMAKE_COMMAND} -E make_directory ${bundle_charts_dir}
- COMMAND ${CMAKE_COMMAND} -E copy_if_different
- $<TARGET_FILE:chartsplugin> ${bundle_charts_dir}
- COMMAND ${CMAKE_COMMAND} -E copy_if_different
- ${chars_qmldir_file} ${bundle_charts_dir}
- VERBATIM
- )
- endif()
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLEDIR}/Charts")
install(TARGETS chartsplugin
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}/Charts"
+ LIBRARY DESTINATION "${CMAKE_INSTALL_BINDIR}/Charts"
)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/qmldir
- DESTINATION "${INSTALL_EXAMPLEDIR}")
+ DESTINATION "${CMAKE_INSTALL_BINDIR}/Charts"
+)
diff --git a/examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/qmldir b/examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/qmldir
index d9e8471b3c..4536f60e91 100644
--- a/examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/qmldir
+++ b/examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/qmldir
@@ -1,2 +1,5 @@
module Charts
-plugin chartsplugin
+optional plugin chartsplugin
+typeinfo plugins.qmltypes
+depends QtQuick
+prefer :/qt/qml/Charts/
diff --git a/examples/qml/tutorials/extending-qml/chapter6-plugins/app.qrc b/examples/qml/tutorials/extending-qml/chapter6-plugins/app.qrc
index f1168aef3b..5c4567d0d9 100644
--- a/examples/qml/tutorials/extending-qml/chapter6-plugins/app.qrc
+++ b/examples/qml/tutorials/extending-qml/chapter6-plugins/app.qrc
@@ -1,5 +1,6 @@
<RCC>
- <qresource prefix="/">
- <file>app.qml</file>
+ <qresource prefix="/qt/qml/ChartsApp">
+ <file>App.qml</file>
+ <file>qmldir</file>
</qresource>
</RCC>
diff --git a/examples/qml/tutorials/extending-qml/chapter6-plugins/main.cpp b/examples/qml/tutorials/extending-qml/chapter6-plugins/main.cpp
index 3475401ebd..7dfb1cf5a7 100644
--- a/examples/qml/tutorials/extending-qml/chapter6-plugins/main.cpp
+++ b/examples/qml/tutorials/extending-qml/chapter6-plugins/main.cpp
@@ -9,12 +9,12 @@ int main(int argc, char *argv[])
QGuiApplication app(argc, argv);
//![0]
QQuickView view;
-#ifdef Q_OS_OSX
+#ifdef Q_OS_MACOS
view.engine()->addImportPath(app.applicationDirPath() + "/../PlugIns");
#endif
//![0]
view.setResizeMode(QQuickView::SizeRootObjectToView);
- view.setSource(QUrl("qrc:///app.qml"));
+ view.loadFromModule("ChartsApp", "App");
view.show();
return app.exec();
}
diff --git a/examples/qml/tutorials/extending-qml/chapter6-plugins/qmldir b/examples/qml/tutorials/extending-qml/chapter6-plugins/qmldir
new file mode 100644
index 0000000000..d7fa4b260b
--- /dev/null
+++ b/examples/qml/tutorials/extending-qml/chapter6-plugins/qmldir
@@ -0,0 +1,3 @@
+module ChartsApp
+prefer :/qt/qml/ChartsApp/
+App 254.0 App.qml
diff --git a/examples/qml/xmlhttprequest/CMakeLists.txt b/examples/qml/xmlhttprequest/CMakeLists.txt
deleted file mode 100644
index 63d15c37dd..0000000000
--- a/examples/qml/xmlhttprequest/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(xmlhttprequest LANGUAGES CXX)
-
-set(CMAKE_AUTOMOC ON)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/qml/xmlhttprequest")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Gui Qml Quick)
-
-qt_add_executable(xmlhttprequestexample
- WIN32
- MACOSX_BUNDLE
- main.cpp
-)
-
-qt_add_qml_module(xmlhttprequestexample
- URI xmlhttprequest
- AUTO_RESOURCE_PREFIX
- QML_FILES
- "methods.js"
- "xmlhttprequest.qml"
- RESOURCES
- data.xml
-)
-
-target_link_libraries(xmlhttprequestexample PUBLIC
- Qt::Core
- Qt::Gui
- Qt::Qml
- Qt::Quick
-)
-
-install(TARGETS xmlhttprequestexample
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/qml/xmlhttprequest/data.xml b/examples/qml/xmlhttprequest/data.xml
deleted file mode 100644
index 8b7f1e116d..0000000000
--- a/examples/qml/xmlhttprequest/data.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-<data>
- <element1 />
- <element2 />
-</data>
-
diff --git a/examples/qml/xmlhttprequest/doc/images/qml-xmlhttprequest-example.png b/examples/qml/xmlhttprequest/doc/images/qml-xmlhttprequest-example.png
deleted file mode 100644
index f585613427..0000000000
--- a/examples/qml/xmlhttprequest/doc/images/qml-xmlhttprequest-example.png
+++ /dev/null
Binary files differ
diff --git a/examples/qml/xmlhttprequest/doc/src/xmlhttprequest.qdoc b/examples/qml/xmlhttprequest/doc/src/xmlhttprequest.qdoc
deleted file mode 100644
index fc6ca600cd..0000000000
--- a/examples/qml/xmlhttprequest/doc/src/xmlhttprequest.qdoc
+++ /dev/null
@@ -1,20 +0,0 @@
-// Copyright (C) 2017 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
-/*!
- \title Qt Quick Examples - XMLHttpRequest
- \example xmlhttprequest
- \brief This is a collection of XMLHttpRequest examples.
- \image qml-xmlhttprequest-example.png
-
- \e XMLHttpRequest contains a small QML example demonstrating \l{Qt QML}'s
- XMLHttpRequest functionality. For more information, visit the section about
- \l{QML Global Object#XMLHttpRequest}{XMLHttpRequest}.
-
- \include examples-run.qdocinc
-
- \section1 Get Data
-
- \e{Get data} uses the XMLHttpRequest API to fetch an XML document from a
- server. It displays the header of the HTTP response and the body of the XML
- document.
-*/
diff --git a/examples/qml/xmlhttprequest/main.cpp b/examples/qml/xmlhttprequest/main.cpp
deleted file mode 100644
index f76ca49de5..0000000000
--- a/examples/qml/xmlhttprequest/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 <QDir>
-#include <QGuiApplication>
-#include <QQmlFileSelector>
-#include <QQuickView>
-
-int main(int argc, char *argv[])
-{
- QGuiApplication app(argc, argv);
- app.setOrganizationName("QtProject");
- app.setOrganizationDomain("qt-project.org");
- app.setApplicationName(QFileInfo(app.applicationFilePath()).baseName());
- QQuickView view;
-
- qputenv("QML_XHR_ALLOW_FILE_READ", QByteArray("1"));
-
- view.connect(view.engine(), &QQmlEngine::quit, &app, &QCoreApplication::quit);
- view.setSource(QUrl("qrc:/qt/qml/xmlhttprequest/xmlhttprequest.qml"));
- if (view.status() == QQuickView::Error)
- return -1;
- view.setResizeMode(QQuickView::SizeRootObjectToView);
- view.show();
- return app.exec();
-}
diff --git a/examples/qml/xmlhttprequest/methods.js b/examples/qml/xmlhttprequest/methods.js
deleted file mode 100644
index 12bde365b2..0000000000
--- a/examples/qml/xmlhttprequest/methods.js
+++ /dev/null
@@ -1,34 +0,0 @@
-// Copyright (C) 2017 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-function showRequestInfo(text) {
- msg.text = msg.text + "\n" + text
-}
-
-function makeRequest()
-{
-
- var doc = new XMLHttpRequest();
- msg.text = "";
- doc.onreadystatechange = function() {
- if (doc.readyState == XMLHttpRequest.HEADERS_RECEIVED) {
- showRequestInfo("Headers -->");
- showRequestInfo(doc.getAllResponseHeaders ());
- showRequestInfo("Last modified -->");
- showRequestInfo(doc.getResponseHeader ("Last-Modified"));
-
- } else if (doc.readyState == XMLHttpRequest.DONE) {
- var a = doc.responseXML.documentElement;
- for (var ii = 0; ii < a.childNodes.length; ++ii) {
- showRequestInfo(a.childNodes[ii].nodeName);
- }
- showRequestInfo("Headers -->");
- showRequestInfo(doc.getAllResponseHeaders ());
- showRequestInfo("Last modified -->");
- showRequestInfo(doc.getResponseHeader ("Last-Modified"));
- }
- }
-
- doc.open("GET", "data.xml");
- doc.send();
-}
diff --git a/examples/qml/xmlhttprequest/xmlhttprequest.pro b/examples/qml/xmlhttprequest/xmlhttprequest.pro
deleted file mode 100644
index 6d572fff59..0000000000
--- a/examples/qml/xmlhttprequest/xmlhttprequest.pro
+++ /dev/null
@@ -1,15 +0,0 @@
-TEMPLATE = app
-
-QT += quick qml
-SOURCES += main.cpp
-RESOURCES += \
- xmlhttprequest.qrc
-
-EXAMPLE_FILES = \
- data.xml
-
-target.path = $$[QT_INSTALL_EXAMPLES]/qml/xmlhttprequest
-INSTALLS += target
-
-DISTFILES += \
- methods.js
diff --git a/examples/qml/xmlhttprequest/xmlhttprequest.qml b/examples/qml/xmlhttprequest/xmlhttprequest.qml
deleted file mode 100644
index 434648c16f..0000000000
--- a/examples/qml/xmlhttprequest/xmlhttprequest.qml
+++ /dev/null
@@ -1,28 +0,0 @@
-// Copyright (C) 2021 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-import QtQuick
-import QtQuick.Controls
-import "methods.js" as Utils
-
-
-Item {
- height: 480
- width: 320
-
- property alias msg: ttext
-
- Label { id: ttext; anchors.fill: parent; anchors.margins: 10 }
-
- Button {
- id: button
- anchors.horizontalCenter: parent.horizontalCenter;
- anchors.bottom: parent.bottom
- anchors.margins: 10
- antialiasing: true
-
- text: qsTr("Request data.xml")
-
- onClicked: Utils.makeRequest()
- }
-}
diff --git a/examples/qml/xmlhttprequest/xmlhttprequest.qmlproject b/examples/qml/xmlhttprequest/xmlhttprequest.qmlproject
deleted file mode 100644
index 088042a100..0000000000
--- a/examples/qml/xmlhttprequest/xmlhttprequest.qmlproject
+++ /dev/null
@@ -1,16 +0,0 @@
-import QmlProject 1.0
-
-Project {
- mainFile: "xmlhttprequest.qml"
- /* Include .qml, .js, and image files from current directory and subdirectories */
-
- QmlFiles {
- directory: "."
- }
- JavaScriptFiles {
- directory: "."
- }
- ImageFiles {
- directory: "."
- }
-} \ No newline at end of file
diff --git a/examples/qml/xmlhttprequest/xmlhttprequest.qrc b/examples/qml/xmlhttprequest/xmlhttprequest.qrc
deleted file mode 100644
index 39d2a62393..0000000000
--- a/examples/qml/xmlhttprequest/xmlhttprequest.qrc
+++ /dev/null
@@ -1,7 +0,0 @@
-<RCC>
- <qresource prefix="/qt/qml/xmlhttprequest">
- <file>xmlhttprequest.qml</file>
- <file>methods.js</file>
- <file>data.xml</file>
- </qresource>
-</RCC>