diff options
Diffstat (limited to 'examples/qml')
121 files changed, 652 insertions, 1315 deletions
diff --git a/examples/qml/.prev_CMakeLists.txt b/examples/qml/.prev_CMakeLists.txt deleted file mode 100644 index 0ec4c9b39d..0000000000 --- a/examples/qml/.prev_CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ -# Generated from qml.pro. - -add_subdirectory(referenceexamples) -add_subdirectory(tutorials) -add_subdirectory(shell) -if(TARGET Qt::Quick) - add_subdirectory(qmlextensionplugins) - add_subdirectory(xmlhttprequest) -endif() -if(QT_FEATURE_qml_network AND TARGET Qt::Quick) - add_subdirectory(networkaccessmanagerfactory) -endif() diff --git a/examples/qml/CMakeLists.txt b/examples/qml/CMakeLists.txt index 61e550762d..7f84d6e257 100644 --- a/examples/qml/CMakeLists.txt +++ b/examples/qml/CMakeLists.txt @@ -1,5 +1,6 @@ # Generated from qml.pro. +qt_internal_add_example(dynamicscene) add_subdirectory(referenceexamples) add_subdirectory(tutorials) qt_internal_add_example(shell) diff --git a/examples/qml/doc/src/qml-extending.qdoc b/examples/qml/doc/src/qml-extending.qdoc index c9922ebd45..36d7ee290c 100644 --- a/examples/qml/doc/src/qml-extending.qdoc +++ b/examples/qml/doc/src/qml-extending.qdoc @@ -168,10 +168,12 @@ developed in the previous examples into two types - a \c Boy and a \c Girl. \snippet referenceexamples/coercion/person.h 0 The Person class remains unaltered in this example and the Boy and Girl C++ -classes are trivial extensions of it. 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. +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 @@ -187,15 +189,6 @@ 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. -\section2 Define Boy and Girl - -The implementation of Boy and Girl is trivial. - -\snippet referenceexamples/coercion/person.cpp 1 - -All that is necessary is to implement the constructor, and to register the types -and their QML name with the QML engine. - \section1 Running the Example The BirthdayParty type has not changed since the previous example. The @@ -271,6 +264,12 @@ This example builds on: \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} diff --git a/examples/qml/dynamicscene/CMakeLists.txt b/examples/qml/dynamicscene/CMakeLists.txt new file mode 100644 index 0000000000..623ab1f78b --- /dev/null +++ b/examples/qml/dynamicscene/CMakeLists.txt @@ -0,0 +1,49 @@ +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 COMPONENTS Core Gui Quick Qml) + +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 + VERSION 1.0 + 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/content/GenericSceneItem.qml b/examples/qml/dynamicscene/GenericSceneItem.qml index 3c83169c7a..bc09fd5817 100644 --- a/examples/qml/dynamicscene/content/GenericSceneItem.qml +++ b/examples/qml/dynamicscene/GenericSceneItem.qml @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. @@ -48,7 +48,7 @@ ** ****************************************************************************/ -import QtQuick 2.0 +import QtQuick Image { property bool created: false diff --git a/examples/qml/dynamicscene/content/PaletteItem.qml b/examples/qml/dynamicscene/PaletteItem.qml index ca734a5dba..d6df4be870 100644 --- a/examples/qml/dynamicscene/content/PaletteItem.qml +++ b/examples/qml/dynamicscene/PaletteItem.qml @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. @@ -48,7 +48,7 @@ ** ****************************************************************************/ -import QtQuick 2.0 +import QtQuick import "itemCreation.js" as Code Image { diff --git a/examples/qml/dynamicscene/content/PerspectiveItem.qml b/examples/qml/dynamicscene/PerspectiveItem.qml index a712358000..d02a188043 100644 --- a/examples/qml/dynamicscene/content/PerspectiveItem.qml +++ b/examples/qml/dynamicscene/PerspectiveItem.qml @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. @@ -48,7 +48,7 @@ ** ****************************************************************************/ -import QtQuick 2.0 +import QtQuick Image { id: rootItem diff --git a/examples/qml/dynamicscene/content/Sun.qml b/examples/qml/dynamicscene/Sun.qml index 0e70f3b5db..062a6065e0 100644 --- a/examples/qml/dynamicscene/content/Sun.qml +++ b/examples/qml/dynamicscene/Sun.qml @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. @@ -48,7 +48,7 @@ ** ****************************************************************************/ -import QtQuick 2.0 +import QtQuick Image { id: sun diff --git a/examples/qml/dynamicscene/content/Button.qml b/examples/qml/dynamicscene/content/Button.qml deleted file mode 100644 index d558ef7608..0000000000 --- a/examples/qml/dynamicscene/content/Button.qml +++ /dev/null @@ -1,87 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, you may use this file under the terms of the BSD license -** as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of The Qt Company Ltd nor the names of its -** contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.0 - -Rectangle { - id: container - - property variant text - signal clicked - - height: text.height + 10; width: text.width + 20 - border.width: 1 - radius: 4 - antialiasing: true - - gradient: Gradient { - GradientStop { - position: 0.0 - color: !mouseArea.pressed ? "#eeeeee" : "#888888" - } - GradientStop { - position: 1.0 - color: !mouseArea.pressed ? "#888888" : "#333333" - } - } - - MouseArea { - id: mouseArea - anchors.fill: parent - onClicked: container.clicked() - } - - Text { - id: text - anchors.centerIn:parent - font.pointSize: 10 - text: parent.text - } -} diff --git a/examples/qml/dynamicscene/dynamicscene.qml b/examples/qml/dynamicscene/dynamicscene.qml index d197b95235..0775d7593e 100644 --- a/examples/qml/dynamicscene/dynamicscene.qml +++ b/examples/qml/dynamicscene/dynamicscene.qml @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. @@ -48,9 +48,9 @@ ** ****************************************************************************/ -import QtQuick 2.0 -import QtQuick.Particles 2.0 -import "content" +import QtQuick +import QtQuick.Particles +import QtQuick.Controls Item { id: window @@ -82,7 +82,7 @@ Item { dialogAnim.start(); } - Text { + Label { id: dialogText x: 3; y: 3 font.pixelSize: 14 @@ -119,7 +119,7 @@ Item { ImageParticle { id: stars - source: "content/images/star.png" + source: "images/star.png" groups: ["stars"] opacity: .5 } @@ -156,7 +156,7 @@ Item { anchors.centerIn: parent spacing: 8 - Text { text: "Drag an item into the scene." } + Label { text: "Drag an item into the scene." } Rectangle { width: palette.width + 10; height: palette.height + 10 @@ -170,37 +170,37 @@ Item { PaletteItem { anchors.verticalCenter: parent.verticalCenter componentFile: "Sun.qml" - source: "content/images/sun.png" + source: "images/sun.png" image: "images/sun.png" } PaletteItem { anchors.verticalCenter: parent.verticalCenter componentFile: "GenericSceneItem.qml" - source: "content/images/moon.png" + source: "images/moon.png" image: "images/moon.png" } PaletteItem { anchors.verticalCenter: parent.verticalCenter componentFile: "PerspectiveItem.qml" - source: "content/images/tree_s.png" + source: "images/tree_s.png" image: "images/tree_s.png" } PaletteItem { anchors.verticalCenter: parent.verticalCenter componentFile: "PerspectiveItem.qml" - source: "content/images/rabbit_brown.png" + source: "images/rabbit_brown.png" image: "images/rabbit_brown.png" } PaletteItem { anchors.verticalCenter: parent.verticalCenter componentFile: "PerspectiveItem.qml" - source: "content/images/rabbit_bw.png" + source: "images/rabbit_bw.png" image: "images/rabbit_bw.png" } } } - Text { text: "Active Suns: " + window.activeSuns } + Label { text: "Active Suns: " + window.activeSuns } } } @@ -226,7 +226,7 @@ Item { Row { height: createButton.height spacing: 8 - Text { text: "Custom QML:"; anchors.verticalCenter: parent.verticalCenter } + Label { text: "Custom QML:"; anchors.verticalCenter: parent.verticalCenter } Button { id: popupButton text: popupToolbox.poppedUp ? "Hide" : "Show" @@ -249,7 +249,7 @@ Item { Rectangle { width: 360; height: 240 - TextEdit { + TextArea { id: qmlText anchors.fill: parent; anchors.margins: 5 readOnly: false @@ -257,7 +257,7 @@ Item { selectByMouse: true wrapMode: TextEdit.WordWrap - text: "import QtQuick 2.0\nImage {\n id: smile\n x: 360 * Math.random()\n y: 40 * Math.random() \n source: 'content/images/face-smile.png'\n NumberAnimation on opacity { \n to: 0; duration: 1500\n }\n Component.onCompleted: smile.destroy(1500);\n}" + text: "import QtQuick 2.0\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}" } } } diff --git a/examples/qml/dynamicscene/dynamicscene.qrc b/examples/qml/dynamicscene/dynamicscene.qrc index ac9baa4941..052b9f8536 100644 --- a/examples/qml/dynamicscene/dynamicscene.qrc +++ b/examples/qml/dynamicscene/dynamicscene.qrc @@ -1,19 +1,18 @@ <RCC> - <qresource prefix="/"> + <qresource prefix="/dynamicscene"> <file>dynamicscene.qml</file> - <file>content/images/face-smile.png</file> - <file>content/images/moon.png</file> - <file>content/images/NOTE</file> - <file>content/images/rabbit_brown.png</file> - <file>content/images/rabbit_bw.png</file> - <file>content/images/star.png</file> - <file>content/images/sun.png</file> - <file>content/images/tree_s.png</file> - <file>content/Button.qml</file> - <file>content/GenericSceneItem.qml</file> - <file>content/itemCreation.js</file> - <file>content/PaletteItem.qml</file> - <file>content/PerspectiveItem.qml</file> - <file>content/Sun.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/content/images/NOTE b/examples/qml/dynamicscene/images/NOTE index fcd87f9132..fcd87f9132 100644 --- a/examples/qml/dynamicscene/content/images/NOTE +++ b/examples/qml/dynamicscene/images/NOTE diff --git a/examples/qml/dynamicscene/content/images/face-smile.png b/examples/qml/dynamicscene/images/face-smile.png Binary files differindex 3d66d72578..3d66d72578 100644 --- a/examples/qml/dynamicscene/content/images/face-smile.png +++ b/examples/qml/dynamicscene/images/face-smile.png diff --git a/examples/qml/dynamicscene/content/images/moon.png b/examples/qml/dynamicscene/images/moon.png Binary files differindex 1c0d6066a8..1c0d6066a8 100644 --- a/examples/qml/dynamicscene/content/images/moon.png +++ b/examples/qml/dynamicscene/images/moon.png diff --git a/examples/qml/dynamicscene/content/images/rabbit_brown.png b/examples/qml/dynamicscene/images/rabbit_brown.png Binary files differindex ebfdeed332..ebfdeed332 100644 --- a/examples/qml/dynamicscene/content/images/rabbit_brown.png +++ b/examples/qml/dynamicscene/images/rabbit_brown.png diff --git a/examples/qml/dynamicscene/content/images/rabbit_bw.png b/examples/qml/dynamicscene/images/rabbit_bw.png Binary files differindex 7bff9b92ca..7bff9b92ca 100644 --- a/examples/qml/dynamicscene/content/images/rabbit_bw.png +++ b/examples/qml/dynamicscene/images/rabbit_bw.png diff --git a/examples/qml/dynamicscene/content/images/star.png b/examples/qml/dynamicscene/images/star.png Binary files differindex bdcd36909d..bdcd36909d 100644 --- a/examples/qml/dynamicscene/content/images/star.png +++ b/examples/qml/dynamicscene/images/star.png diff --git a/examples/qml/dynamicscene/content/images/sun.png b/examples/qml/dynamicscene/images/sun.png Binary files differindex c5fd36ed39..c5fd36ed39 100644 --- a/examples/qml/dynamicscene/content/images/sun.png +++ b/examples/qml/dynamicscene/images/sun.png diff --git a/examples/qml/dynamicscene/content/images/tree_s.png b/examples/qml/dynamicscene/images/tree_s.png Binary files differindex 6eac35a729..6eac35a729 100644 --- a/examples/qml/dynamicscene/content/images/tree_s.png +++ b/examples/qml/dynamicscene/images/tree_s.png diff --git a/examples/qml/dynamicscene/content/itemCreation.js b/examples/qml/dynamicscene/itemCreation.js index 2829a83410..2829a83410 100644 --- a/examples/qml/dynamicscene/content/itemCreation.js +++ b/examples/qml/dynamicscene/itemCreation.js diff --git a/examples/qml/dynamicscene/main.cpp b/examples/qml/dynamicscene/main.cpp index e28375158d..f6d2ee9a78 100644 --- a/examples/qml/dynamicscene/main.cpp +++ b/examples/qml/dynamicscene/main.cpp @@ -48,4 +48,4 @@ ** ****************************************************************************/ #include "../../quick/shared/shared.h" -DECLARATIVE_EXAMPLE_MAIN(dynamicscene) +DECLARATIVE_EXAMPLE_MAIN(dynamicscene/dynamicscene) diff --git a/examples/qml/networkaccessmanagerfactory/CMakeLists.txt b/examples/qml/networkaccessmanagerfactory/CMakeLists.txt index 11a88738ab..fd4444a99b 100644 --- a/examples/qml/networkaccessmanagerfactory/CMakeLists.txt +++ b/examples/qml/networkaccessmanagerfactory/CMakeLists.txt @@ -1,6 +1,6 @@ # Generated from networkaccessmanagerfactory.pro. -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(networkaccessmanagerfactory LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) @@ -36,17 +36,11 @@ target_link_libraries(networkaccessmanagerfactory PUBLIC Qt::Quick ) - -# Resources: -set(networkaccessmanagerfactory_resource_files - "view.qml" -) - -qt6_add_resources(networkaccessmanagerfactory "networkaccessmanagerfactory" - PREFIX - "/" - FILES - ${networkaccessmanagerfactory_resource_files} +qt_add_qml_module(networkaccessmanagerfactory + URI Example + VERSION 1.0 + QML_FILES view.qml + NO_RESOURCE_TARGET_PATH ) install(TARGETS networkaccessmanagerfactory diff --git a/examples/qml/qmlextensionplugins/CMakeLists.txt b/examples/qml/qmlextensionplugins/CMakeLists.txt index 6ea73f83a4..8156f23eb1 100644 --- a/examples/qml/qmlextensionplugins/CMakeLists.txt +++ b/examples/qml/qmlextensionplugins/CMakeLists.txt @@ -1,6 +1,6 @@ # Generated from qmlextensionplugins.pro. -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(qmlqtimeexample LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) @@ -14,20 +14,32 @@ if(NOT DEFINED INSTALL_EXAMPLESDIR) endif() set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/qml/qmlextensionplugins/imports/TimeExample") -set(QT_QML_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/examples/qml/qmlextensionplugins/imports) find_package(Qt6 COMPONENTS Core) find_package(Qt6 COMPONENTS Gui) find_package(Qt6 COMPONENTS Qml) -set_source_files_properties(imports/TimeExample/Clock.qml PROPERTIES - QT_RESOURCE_ALIAS Clock.qml +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 +) +foreach(file IN LISTS qml_files images) + get_filename_component(filename ${file} NAME) + set_source_files_properties(${file} PROPERTIES QT_RESOURCE_ALIAS ${filename}) +endforeach() + qt6_add_qml_module(qmlqtimeexample + OUTPUT_DIRECTORY TimeExample VERSION 1.0 URI "TimeExample" SOURCES timemodel.cpp timemodel.h - QML_FILES imports/TimeExample/Clock.qml + QML_FILES ${qml_files} + RESOURCES ${images} ) set_target_properties(qmlqtimeexample PROPERTIES WIN32_EXECUTABLE TRUE @@ -39,16 +51,6 @@ target_link_libraries(qmlqtimeexample PUBLIC Qt::Qml ) -qt6_add_resources(qmlqtimeexample example_images - PREFIX "/TimeExample" - BASE imports/TimeExample - FILES - imports/TimeExample/center.png - imports/TimeExample/clock.png - imports/TimeExample/hour.png - imports/TimeExample/minute.png -) - install(TARGETS qmlqtimeexample RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" diff --git a/examples/qml/qmlextensionplugins/doc/src/qmlpluginex.qdoc b/examples/qml/qmlextensionplugins/doc/src/qmlpluginex.qdoc index 24d6991d52..cbc7de2936 100644 --- a/examples/qml/qmlextensionplugins/doc/src/qmlpluginex.qdoc +++ b/examples/qml/qmlextensionplugins/doc/src/qmlpluginex.qdoc @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the documentation of the Qt Toolkit. @@ -37,6 +37,6 @@ \code > qmake > make - > qmlscene -I imports plugins.qml + > qml -I imports plugins.qml \endcode */ diff --git a/examples/qml/referenceexamples/adding/CMakeLists.txt b/examples/qml/referenceexamples/adding/CMakeLists.txt index 9e04f3799a..b86d90a4c3 100644 --- a/examples/qml/referenceexamples/adding/CMakeLists.txt +++ b/examples/qml/referenceexamples/adding/CMakeLists.txt @@ -1,6 +1,6 @@ # Generated from adding.pro. -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(adding LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) @@ -31,17 +31,11 @@ target_link_libraries(adding PUBLIC Qt::Qml ) - -# Resources: -set(adding_resource_files - "example.qml" -) - -qt6_add_resources(adding "adding" - PREFIX - "/" - FILES - ${adding_resource_files} +qt_add_qml_module(adding + URI People + VERSION 1.0 + QML_FILES example.qml + NO_RESOURCE_TARGET_PATH ) install(TARGETS adding @@ -49,10 +43,3 @@ install(TARGETS adding BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) - -set_target_properties(adding PROPERTIES - QT_QML_MODULE_VERSION 1.0 - QT_QML_MODULE_URI People -) - -qt6_qml_type_registration(adding) diff --git a/examples/qml/referenceexamples/adding/main.cpp b/examples/qml/referenceexamples/adding/main.cpp index 6c3920f04b..fbf3e71af7 100644 --- a/examples/qml/referenceexamples/adding/main.cpp +++ b/examples/qml/referenceexamples/adding/main.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. @@ -47,6 +47,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ + #include <QCoreApplication> #include <QQmlEngine> #include <QQmlComponent> @@ -60,12 +61,13 @@ int main(int argc, char ** argv) QQmlEngine engine; QQmlComponent component(&engine, QUrl("qrc:example.qml")); auto *person = qobject_cast<Person *>(component.create()); - if (person) { - qWarning() << "The person's name is" << person->name(); - qWarning() << "They wear a" << person->shoeSize() << "sized shoe"; - } else { + 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 index de4a33dd00..4741442cf0 100644 --- a/examples/qml/referenceexamples/adding/person.cpp +++ b/examples/qml/referenceexamples/adding/person.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. @@ -47,14 +47,10 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ + #include "person.h" // ![0] -Person::Person(QObject *parent) -: QObject(parent), m_shoeSize(0) -{ -} - QString Person::name() const { return m_name; diff --git a/examples/qml/referenceexamples/adding/person.h b/examples/qml/referenceexamples/adding/person.h index 530c335dee..03a72d184f 100644 --- a/examples/qml/referenceexamples/adding/person.h +++ b/examples/qml/referenceexamples/adding/person.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. @@ -47,6 +47,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ + #ifndef PERSON_H #define PERSON_H @@ -61,7 +62,7 @@ class Person : public QObject Q_PROPERTY(int shoeSize READ shoeSize WRITE setShoeSize) QML_ELEMENT public: - Person(QObject *parent = nullptr); + using QObject::QObject; QString name() const; void setName(const QString &); @@ -71,7 +72,7 @@ public: private: QString m_name; - int m_shoeSize; + int m_shoeSize = 0; }; //![0] diff --git a/examples/qml/referenceexamples/attached/CMakeLists.txt b/examples/qml/referenceexamples/attached/CMakeLists.txt index 10aa52293c..4d49cc5663 100644 --- a/examples/qml/referenceexamples/attached/CMakeLists.txt +++ b/examples/qml/referenceexamples/attached/CMakeLists.txt @@ -1,6 +1,6 @@ # Generated from attached.pro. -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(attached LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) @@ -34,17 +34,11 @@ target_link_libraries(attached PUBLIC Qt::Qml ) - -# Resources: -set(attached_resource_files - "example.qml" -) - -qt6_add_resources(attached "attached" - PREFIX - "/" - FILES - ${attached_resource_files} +qt_add_qml_module(attached + URI People + VERSION 1.0 + QML_FILES example.qml + NO_RESOURCE_TARGET_PATH ) install(TARGETS attached @@ -52,10 +46,3 @@ install(TARGETS attached BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) - -set_target_properties(attached PROPERTIES - QT_QML_MODULE_VERSION 1.0 - QT_QML_MODULE_URI People -) - -qt6_qml_type_registration(attached) diff --git a/examples/qml/referenceexamples/attached/birthdayparty.cpp b/examples/qml/referenceexamples/attached/birthdayparty.cpp index 9aed5df621..fc27a22631 100644 --- a/examples/qml/referenceexamples/attached/birthdayparty.cpp +++ b/examples/qml/referenceexamples/attached/birthdayparty.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. @@ -47,12 +47,8 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ -#include "birthdayparty.h" -BirthdayPartyAttached::BirthdayPartyAttached(QObject *object) -: QObject(object) -{ -} +#include "birthdayparty.h" QDate BirthdayPartyAttached::rsvp() const { @@ -64,11 +60,6 @@ void BirthdayPartyAttached::setRsvp(QDate d) m_rsvp = d; } -BirthdayParty::BirthdayParty(QObject *parent) -: QObject(parent), m_host(nullptr) -{ -} - Person *BirthdayParty::host() const { return m_host; @@ -84,12 +75,12 @@ QQmlListProperty<Person> BirthdayParty::guests() return {this, &m_guests}; } -int BirthdayParty::guestCount() const +qsizetype BirthdayParty::guestCount() const { return m_guests.count(); } -Person *BirthdayParty::guest(int index) const +Person *BirthdayParty::guest(qsizetype index) const { return m_guests.at(index); } diff --git a/examples/qml/referenceexamples/attached/birthdayparty.h b/examples/qml/referenceexamples/attached/birthdayparty.h index 4f2ed1702a..30f5cbbb64 100644 --- a/examples/qml/referenceexamples/attached/birthdayparty.h +++ b/examples/qml/referenceexamples/attached/birthdayparty.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. @@ -47,6 +47,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ + #ifndef BIRTHDAYPARTY_H #define BIRTHDAYPARTY_H @@ -61,7 +62,7 @@ class BirthdayPartyAttached : public QObject Q_PROPERTY(QDate rsvp READ rsvp WRITE setRsvp) QML_ANONYMOUS public: - BirthdayPartyAttached(QObject *object); + using QObject::QObject; QDate rsvp() const; void setRsvp(QDate); @@ -83,20 +84,20 @@ class BirthdayParty : public QObject //! [declare attached] public: - BirthdayParty(QObject *parent = nullptr); + using QObject::QObject; Person *host() const; void setHost(Person *); QQmlListProperty<Person> guests(); - int guestCount() const; - Person *guest(int) const; + qsizetype guestCount() const; + Person *guest(qsizetype) const; //! [static attached] static BirthdayPartyAttached *qmlAttachedProperties(QObject *); //! [static attached] private: - Person *m_host; + Person *m_host = nullptr; QList<Person *> m_guests; }; diff --git a/examples/qml/referenceexamples/attached/main.cpp b/examples/qml/referenceexamples/attached/main.cpp index 2fceb98ac9..5f8497bed3 100644 --- a/examples/qml/referenceexamples/attached/main.cpp +++ b/examples/qml/referenceexamples/attached/main.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. @@ -47,6 +47,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ + #include <QCoreApplication> #include <QQmlEngine> #include <QQmlComponent> @@ -63,14 +64,14 @@ int main(int argc, char ** argv) auto *party = qobject_cast<BirthdayParty *>(component.create()); if (party && party->host()) { - qWarning() << party->host()->name() << "is having a birthday!"; + qInfo() << party->host()->name() << "is having a birthday!"; if (qobject_cast<Boy *>(party->host())) - qWarning() << "He is inviting:"; + qInfo() << "He is inviting:"; else - qWarning() << "She is inviting:"; + qInfo() << "She is inviting:"; - for (int ii = 0; ii < party->guestCount(); ++ii) { + for (qsizetype ii = 0; ii < party->guestCount(); ++ii) { Person *guest = party->guest(ii); //! [query rsvp] @@ -81,9 +82,9 @@ int main(int argc, char ** argv) rsvpDate = attached->property("rsvp").toDate(); //! [query rsvp] if (rsvpDate.isNull()) - qWarning() << " " << guest->name() << "RSVP date: Hasn't RSVP'd"; + qInfo() << " " << guest->name() << "RSVP date: Hasn't RSVP'd"; else - qWarning() << " " << guest->name() << "RSVP date:" << qPrintable(rsvpDate.toString()); + qInfo() << " " << guest->name() << "RSVP date:" << rsvpDate.toString(); } return EXIT_SUCCESS; diff --git a/examples/qml/referenceexamples/attached/person.cpp b/examples/qml/referenceexamples/attached/person.cpp index 0603644108..4e52da76c8 100644 --- a/examples/qml/referenceexamples/attached/person.cpp +++ b/examples/qml/referenceexamples/attached/person.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. @@ -47,12 +47,8 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ -#include "person.h" -ShoeDescription::ShoeDescription(QObject *parent) -: QObject(parent), m_size(0), m_price(0) -{ -} +#include "person.h" int ShoeDescription::size() const { @@ -94,11 +90,6 @@ void ShoeDescription::setPrice(qreal p) m_price = p; } -Person::Person(QObject *parent) -: QObject(parent) -{ -} - QString Person::name() const { return m_name; @@ -113,16 +104,3 @@ ShoeDescription *Person::shoe() { return &m_shoe; } - - -Boy::Boy(QObject * parent) -: Person(parent) -{ -} - - -Girl::Girl(QObject * parent) -: Person(parent) -{ -} - diff --git a/examples/qml/referenceexamples/attached/person.h b/examples/qml/referenceexamples/attached/person.h index 239f4405c0..ddd3baa5f2 100644 --- a/examples/qml/referenceexamples/attached/person.h +++ b/examples/qml/referenceexamples/attached/person.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. @@ -47,6 +47,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ + #ifndef PERSON_H #define PERSON_H @@ -63,7 +64,7 @@ class ShoeDescription : public QObject Q_PROPERTY(qreal price READ price WRITE setPrice) QML_ANONYMOUS public: - ShoeDescription(QObject *parent = 0); + using QObject::QObject; int size() const; void setSize(int); @@ -76,11 +77,12 @@ public: qreal price() const; void setPrice(qreal); + private: - int m_size; + int m_size = 0; QColor m_color; QString m_brand; - qreal m_price; + qreal m_price = 0; }; class Person : public QObject @@ -90,7 +92,7 @@ class Person : public QObject Q_PROPERTY(ShoeDescription *shoe READ shoe) QML_ANONYMOUS public: - Person(QObject *parent = nullptr); + using QObject::QObject; QString name() const; void setName(const QString &); @@ -106,7 +108,7 @@ class Boy : public Person Q_OBJECT QML_ELEMENT public: - Boy(QObject * parent = nullptr); + using Person::Person; }; class Girl : public Person @@ -114,7 +116,7 @@ class Girl : public Person Q_OBJECT QML_ELEMENT public: - Girl(QObject * parent = nullptr); + using Person::Person; }; #endif // PERSON_H diff --git a/examples/qml/referenceexamples/binding/CMakeLists.txt b/examples/qml/referenceexamples/binding/CMakeLists.txt index f64c24803c..2a2d6575c0 100644 --- a/examples/qml/referenceexamples/binding/CMakeLists.txt +++ b/examples/qml/referenceexamples/binding/CMakeLists.txt @@ -1,6 +1,6 @@ # Generated from binding.pro. -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(binding LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) @@ -35,17 +35,11 @@ target_link_libraries(binding PUBLIC Qt::Qml ) - -# Resources: -set(binding_resource_files - "example.qml" -) - -qt6_add_resources(binding "binding" - PREFIX - "/" - FILES - ${binding_resource_files} +qt_add_qml_module(binding + URI People + VERSION 1.0 + QML_FILES example.qml + NO_RESOURCE_TARGET_PATH ) install(TARGETS binding @@ -53,10 +47,3 @@ install(TARGETS binding BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) - -set_target_properties(binding PROPERTIES - QT_QML_MODULE_VERSION 1.0 - QT_QML_MODULE_URI People -) - -qt6_qml_type_registration(binding) diff --git a/examples/qml/referenceexamples/binding/birthdayparty.cpp b/examples/qml/referenceexamples/binding/birthdayparty.cpp index 02a1adbb35..ce86c7faa4 100644 --- a/examples/qml/referenceexamples/binding/birthdayparty.cpp +++ b/examples/qml/referenceexamples/binding/birthdayparty.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. @@ -47,12 +47,8 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ -#include "birthdayparty.h" -BirthdayPartyAttached::BirthdayPartyAttached(QObject *object) -: QObject(object) -{ -} +#include "birthdayparty.h" QDate BirthdayPartyAttached::rsvp() const { @@ -67,12 +63,6 @@ void BirthdayPartyAttached::setRsvp(QDate d) } } - -BirthdayParty::BirthdayParty(QObject *parent) -: QObject(parent), m_host(nullptr) -{ -} - Person *BirthdayParty::host() const { return m_host; @@ -90,12 +80,12 @@ QQmlListProperty<Person> BirthdayParty::guests() return QQmlListProperty<Person>(this, &m_guests); } -int BirthdayParty::guestCount() const +qsizetype BirthdayParty::guestCount() const { return m_guests.count(); } -Person *BirthdayParty::guest(int index) const +Person *BirthdayParty::guest(qsizetype index) const { return m_guests.at(index); } @@ -113,7 +103,7 @@ QString BirthdayParty::announcement() const void BirthdayParty::setAnnouncement(const QString &speak) { - qWarning() << qPrintable(speak); + qWarning().noquote() << speak; } BirthdayPartyAttached *BirthdayParty::qmlAttachedProperties(QObject *object) diff --git a/examples/qml/referenceexamples/binding/birthdayparty.h b/examples/qml/referenceexamples/binding/birthdayparty.h index 846a016cfc..2881dfead2 100644 --- a/examples/qml/referenceexamples/binding/birthdayparty.h +++ b/examples/qml/referenceexamples/binding/birthdayparty.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. @@ -47,6 +47,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ + #ifndef BIRTHDAYPARTY_H #define BIRTHDAYPARTY_H @@ -62,7 +63,7 @@ class BirthdayPartyAttached : public QObject Q_PROPERTY(QDate rsvp READ rsvp WRITE setRsvp NOTIFY rsvpChanged) QML_ANONYMOUS public: - BirthdayPartyAttached(QObject *object); + using QObject::QObject; QDate rsvp() const; void setRsvp(QDate); @@ -86,14 +87,14 @@ class BirthdayParty : public QObject QML_ELEMENT QML_ATTACHED(BirthdayPartyAttached) public: - BirthdayParty(QObject *parent = nullptr); + using QObject::QObject; Person *host() const; void setHost(Person *); QQmlListProperty<Person> guests(); - int guestCount() const; - Person *guest(int) const; + qsizetype guestCount() const; + Person *guest(qsizetype) const; QString announcement() const; void setAnnouncement(const QString &); @@ -106,7 +107,7 @@ signals: void hostChanged(); private: - Person *m_host; + Person *m_host = nullptr; QList<Person *> m_guests; }; diff --git a/examples/qml/referenceexamples/binding/happybirthdaysong.cpp b/examples/qml/referenceexamples/binding/happybirthdaysong.cpp index 5f8e6d696e..2722b65e06 100644 --- a/examples/qml/referenceexamples/binding/happybirthdaysong.cpp +++ b/examples/qml/referenceexamples/binding/happybirthdaysong.cpp @@ -50,10 +50,9 @@ #include "happybirthdaysong.h" #include <QTimer> -HappyBirthdaySong::HappyBirthdaySong(QObject *parent) -: QObject(parent), m_line(-1) +HappyBirthdaySong::HappyBirthdaySong(QObject *parent) : + QObject(parent) { - setName(QString()); auto *timer = new QTimer(this); QObject::connect(timer, &QTimer::timeout, this, &HappyBirthdaySong::advance); timer->start(1000); diff --git a/examples/qml/referenceexamples/binding/happybirthdaysong.h b/examples/qml/referenceexamples/binding/happybirthdaysong.h index c84e9d9e5e..078bdac72b 100644 --- a/examples/qml/referenceexamples/binding/happybirthdaysong.h +++ b/examples/qml/referenceexamples/binding/happybirthdaysong.h @@ -64,7 +64,7 @@ class HappyBirthdaySong : public QObject, public QQmlPropertyValueSource Q_INTERFACES(QQmlPropertyValueSource) QML_ELEMENT public: - HappyBirthdaySong(QObject *parent = nullptr); + explicit HappyBirthdaySong(QObject *parent = nullptr); void setTarget(const QQmlProperty &) override; @@ -77,7 +77,7 @@ private slots: signals: void nameChanged(); private: - int m_line; + qsizetype m_line = -1; QStringList m_lyrics; QQmlProperty m_target; QString m_name; diff --git a/examples/qml/referenceexamples/binding/main.cpp b/examples/qml/referenceexamples/binding/main.cpp index 2e9995fcd8..a100497659 100644 --- a/examples/qml/referenceexamples/binding/main.cpp +++ b/examples/qml/referenceexamples/binding/main.cpp @@ -64,14 +64,14 @@ int main(int argc, char ** argv) auto *party = qobject_cast<BirthdayParty *>(component.create()); if (party && party->host()) { - qWarning() << party->host()->name() << "is having a birthday!"; + qInfo() << party->host()->name() << "is having a birthday!"; if (qobject_cast<Boy *>(party->host())) - qWarning() << "He is inviting:"; + qInfo() << "He is inviting:"; else - qWarning() << "She is inviting:"; + qInfo() << "She is inviting:"; - for (int ii = 0; ii < party->guestCount(); ++ii) { + for (qsizetype ii = 0; ii < party->guestCount(); ++ii) { Person *guest = party->guest(ii); QDate rsvpDate; @@ -81,9 +81,9 @@ int main(int argc, char ** argv) rsvpDate = attached->property("rsvp").toDate(); if (rsvpDate.isNull()) - qWarning() << " " << guest->name() << "RSVP date: Hasn't RSVP'd"; + qInfo() << " " << guest->name() << "RSVP date: Hasn't RSVP'd"; else - qWarning() << " " << guest->name() << "RSVP date:" << qPrintable(rsvpDate.toString()); + qInfo() << " " << guest->name() << "RSVP date:" << rsvpDate.toString(); } party->startParty(); diff --git a/examples/qml/referenceexamples/binding/person.cpp b/examples/qml/referenceexamples/binding/person.cpp index 1a23d0a4f5..0296b0a7c6 100644 --- a/examples/qml/referenceexamples/binding/person.cpp +++ b/examples/qml/referenceexamples/binding/person.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. @@ -47,12 +47,8 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ -#include "person.h" -ShoeDescription::ShoeDescription(QObject *parent) -: QObject(parent), m_size(0), m_price(0) -{ -} +#include "person.h" int ShoeDescription::size() const { @@ -110,11 +106,6 @@ void ShoeDescription::setPrice(qreal p) emit shoeChanged(); } -Person::Person(QObject *parent) -: QObject(parent) -{ -} - QString Person::name() const { return m_name; @@ -133,16 +124,3 @@ ShoeDescription *Person::shoe() { return &m_shoe; } - - -Boy::Boy(QObject * parent) -: Person(parent) -{ -} - - -Girl::Girl(QObject * parent) -: Person(parent) -{ -} - diff --git a/examples/qml/referenceexamples/binding/person.h b/examples/qml/referenceexamples/binding/person.h index af9864950a..e84075bb36 100644 --- a/examples/qml/referenceexamples/binding/person.h +++ b/examples/qml/referenceexamples/binding/person.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. @@ -47,6 +47,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ + #ifndef PERSON_H #define PERSON_H @@ -63,7 +64,7 @@ class ShoeDescription : public QObject Q_PROPERTY(qreal price READ price WRITE setPrice NOTIFY shoeChanged) QML_ANONYMOUS public: - ShoeDescription(QObject *parent = nullptr); + using QObject::QObject; int size() const; void setSize(int); @@ -76,14 +77,15 @@ public: qreal price() const; void setPrice(qreal); + signals: void shoeChanged(); private: - int m_size; + int m_size = 0; QColor m_color; QString m_brand; - qreal m_price; + qreal m_price = 0; }; class Person : public QObject @@ -95,12 +97,13 @@ class Person : public QObject // ![0] QML_ANONYMOUS public: - Person(QObject *parent = nullptr); + using QObject::QObject; QString name() const; void setName(const QString &); ShoeDescription *shoe(); + signals: void nameChanged(); @@ -114,7 +117,7 @@ class Boy : public Person Q_OBJECT QML_ELEMENT public: - Boy(QObject * parent = nullptr); + using Person::Person; }; class Girl : public Person @@ -122,7 +125,7 @@ class Girl : public Person Q_OBJECT QML_ELEMENT public: - Girl(QObject * parent = nullptr); + using Person::Person; }; #endif // PERSON_H diff --git a/examples/qml/referenceexamples/coercion/CMakeLists.txt b/examples/qml/referenceexamples/coercion/CMakeLists.txt index 3160b92782..b9613de116 100644 --- a/examples/qml/referenceexamples/coercion/CMakeLists.txt +++ b/examples/qml/referenceexamples/coercion/CMakeLists.txt @@ -1,6 +1,6 @@ # Generated from coercion.pro. -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(coercion LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) @@ -32,17 +32,11 @@ target_link_libraries(coercion PUBLIC Qt::Qml ) - -# Resources: -set(coercion_resource_files - "example.qml" -) - -qt6_add_resources(coercion "coercion" - PREFIX - "/" - FILES - ${coercion_resource_files} +qt_add_qml_module(coercion + URI People + VERSION 1.0 + QML_FILES example.qml + NO_RESOURCE_TARGET_PATH ) install(TARGETS coercion @@ -50,10 +44,3 @@ install(TARGETS coercion BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) - -set_target_properties(coercion PROPERTIES - QT_QML_MODULE_VERSION 1.0 - QT_QML_MODULE_URI People -) - -qt6_qml_type_registration(coercion) diff --git a/examples/qml/referenceexamples/coercion/birthdayparty.cpp b/examples/qml/referenceexamples/coercion/birthdayparty.cpp index 81db8ab1b8..269f45e02c 100644 --- a/examples/qml/referenceexamples/coercion/birthdayparty.cpp +++ b/examples/qml/referenceexamples/coercion/birthdayparty.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. @@ -47,12 +47,8 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ -#include "birthdayparty.h" -BirthdayParty::BirthdayParty(QObject *parent) -: QObject(parent), m_host(nullptr) -{ -} +#include "birthdayparty.h" Person *BirthdayParty::host() const { @@ -69,13 +65,12 @@ QQmlListProperty<Person> BirthdayParty::guests() return {this, &m_guests}; } -int BirthdayParty::guestCount() const +qsizetype BirthdayParty::guestCount() const { return m_guests.count(); } -Person *BirthdayParty::guest(int index) const +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 index ba8b2445f1..a504479e4d 100644 --- a/examples/qml/referenceexamples/coercion/birthdayparty.h +++ b/examples/qml/referenceexamples/coercion/birthdayparty.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. @@ -47,6 +47,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ + #ifndef BIRTHDAYPARTY_H #define BIRTHDAYPARTY_H @@ -63,17 +64,17 @@ class BirthdayParty : public QObject QML_ELEMENT // ![0] public: - BirthdayParty(QObject *parent = nullptr); + using QObject::QObject; Person *host() const; void setHost(Person *); QQmlListProperty<Person> guests(); - int guestCount() const; - Person *guest(int) const; + qsizetype guestCount() const; + Person *guest(qsizetype) const; private: - Person *m_host; + Person *m_host = nullptr; QList<Person *> m_guests; }; diff --git a/examples/qml/referenceexamples/coercion/main.cpp b/examples/qml/referenceexamples/coercion/main.cpp index 6b47d0d4c4..095602af9d 100644 --- a/examples/qml/referenceexamples/coercion/main.cpp +++ b/examples/qml/referenceexamples/coercion/main.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. @@ -47,6 +47,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ + #include <QCoreApplication> #include <QQmlEngine> #include <QQmlComponent> @@ -63,15 +64,15 @@ int main(int argc, char ** argv) auto *party = qobject_cast<BirthdayParty *>(component.create()); if (party && party->host()) { - qWarning() << party->host()->name() << "is having a birthday!"; + qInfo() << party->host()->name() << "is having a birthday!"; if (qobject_cast<Boy *>(party->host())) - qWarning() << "He is inviting:"; + qInfo() << "He is inviting:"; else - qWarning() << "She is inviting:"; + qInfo() << "She is inviting:"; - for (int ii = 0; ii < party->guestCount(); ++ii) - qWarning() << " " << party->guest(ii)->name(); + for (qsizetype ii = 0; ii < party->guestCount(); ++ii) + qInfo() << " " << party->guest(ii)->name(); return EXIT_SUCCESS; } diff --git a/examples/qml/referenceexamples/coercion/person.cpp b/examples/qml/referenceexamples/coercion/person.cpp index 178d7052ce..e2847a2682 100644 --- a/examples/qml/referenceexamples/coercion/person.cpp +++ b/examples/qml/referenceexamples/coercion/person.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. @@ -47,12 +47,8 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ -#include "person.h" -Person::Person(QObject *parent) -: QObject(parent), m_shoeSize(0) -{ -} +#include "person.h" QString Person::name() const { @@ -73,17 +69,3 @@ void Person::setShoeSize(int s) { m_shoeSize = s; } - -// ![1] -Boy::Boy(QObject * parent) -: Person(parent) -{ -} - - -Girl::Girl(QObject * parent) -: Person(parent) -{ -} - -// ![1] diff --git a/examples/qml/referenceexamples/coercion/person.h b/examples/qml/referenceexamples/coercion/person.h index 7e2828da04..1ec095e841 100644 --- a/examples/qml/referenceexamples/coercion/person.h +++ b/examples/qml/referenceexamples/coercion/person.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. @@ -47,6 +47,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ + #ifndef PERSON_H #define PERSON_H @@ -63,16 +64,17 @@ class Person : public QObject QML_UNCREATABLE("Person is an abstract base class.") //![0] public: - Person(QObject *parent = nullptr); + using QObject::QObject; QString name() const; void setName(const QString &); int shoeSize() const; void setShoeSize(int); + private: QString m_name; - int m_shoeSize; + int m_shoeSize = 0; }; @@ -82,7 +84,7 @@ class Boy : public Person Q_OBJECT QML_ELEMENT public: - Boy(QObject * parent = nullptr); + using Person::Person; }; //! [girl class] @@ -91,7 +93,7 @@ class Girl : public Person Q_OBJECT QML_ELEMENT public: - Girl(QObject * parent = nullptr); + using Person::Person; }; //! [girl class] diff --git a/examples/qml/referenceexamples/default/CMakeLists.txt b/examples/qml/referenceexamples/default/CMakeLists.txt index 6e207f3641..419b14d464 100644 --- a/examples/qml/referenceexamples/default/CMakeLists.txt +++ b/examples/qml/referenceexamples/default/CMakeLists.txt @@ -1,6 +1,6 @@ # Generated from default.pro. -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(default LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) @@ -32,17 +32,11 @@ target_link_libraries(default PUBLIC Qt::Qml ) - -# Resources: -set(default_resource_files - "example.qml" -) - -qt6_add_resources(default "default" - PREFIX - "/" - FILES - ${default_resource_files} +qt_add_qml_module(default + URI People + VERSION 1.0 + QML_FILES example.qml + NO_RESOURCE_TARGET_PATH ) install(TARGETS default @@ -50,10 +44,3 @@ install(TARGETS default BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) - -set_target_properties(default PROPERTIES - QT_QML_MODULE_VERSION 1.0 - QT_QML_MODULE_URI People -) - -qt6_qml_type_registration(default) diff --git a/examples/qml/referenceexamples/default/birthdayparty.cpp b/examples/qml/referenceexamples/default/birthdayparty.cpp index 81db8ab1b8..aeaf6fbd9c 100644 --- a/examples/qml/referenceexamples/default/birthdayparty.cpp +++ b/examples/qml/referenceexamples/default/birthdayparty.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. @@ -47,12 +47,8 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ -#include "birthdayparty.h" -BirthdayParty::BirthdayParty(QObject *parent) -: QObject(parent), m_host(nullptr) -{ -} +#include "birthdayparty.h" Person *BirthdayParty::host() const { @@ -69,12 +65,12 @@ QQmlListProperty<Person> BirthdayParty::guests() return {this, &m_guests}; } -int BirthdayParty::guestCount() const +qsizetype BirthdayParty::guestCount() const { return m_guests.count(); } -Person *BirthdayParty::guest(int index) const +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 index 5eb6c88763..cb12a1510b 100644 --- a/examples/qml/referenceexamples/default/birthdayparty.h +++ b/examples/qml/referenceexamples/default/birthdayparty.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. @@ -47,6 +47,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ + #ifndef BIRTHDAYPARTY_H #define BIRTHDAYPARTY_H @@ -63,17 +64,17 @@ class BirthdayParty : public QObject Q_CLASSINFO("DefaultProperty", "guests") QML_ELEMENT public: - BirthdayParty(QObject *parent = nullptr); + using QObject::QObject; Person *host() const; void setHost(Person *); QQmlListProperty<Person> guests(); - int guestCount() const; - Person *guest(int) const; + qsizetype guestCount() const; + Person *guest(qsizetype) const; private: - Person *m_host; + Person *m_host = nullptr; QList<Person *> m_guests; }; // ![0] diff --git a/examples/qml/referenceexamples/default/main.cpp b/examples/qml/referenceexamples/default/main.cpp index 6b47d0d4c4..82e6f5ba37 100644 --- a/examples/qml/referenceexamples/default/main.cpp +++ b/examples/qml/referenceexamples/default/main.cpp @@ -63,15 +63,15 @@ int main(int argc, char ** argv) auto *party = qobject_cast<BirthdayParty *>(component.create()); if (party && party->host()) { - qWarning() << party->host()->name() << "is having a birthday!"; + qInfo() << party->host()->name() << "is having a birthday!"; if (qobject_cast<Boy *>(party->host())) - qWarning() << "He is inviting:"; + qInfo() << "He is inviting:"; else - qWarning() << "She is inviting:"; + qInfo() << "She is inviting:"; - for (int ii = 0; ii < party->guestCount(); ++ii) - qWarning() << " " << party->guest(ii)->name(); + for (qsizetype ii = 0; ii < party->guestCount(); ++ii) + qInfo() << " " << party->guest(ii)->name(); return EXIT_SUCCESS; } diff --git a/examples/qml/referenceexamples/default/person.cpp b/examples/qml/referenceexamples/default/person.cpp index a1d887a4d0..e2847a2682 100644 --- a/examples/qml/referenceexamples/default/person.cpp +++ b/examples/qml/referenceexamples/default/person.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. @@ -47,12 +47,8 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ -#include "person.h" -Person::Person(QObject *parent) -: QObject(parent), m_shoeSize(0) -{ -} +#include "person.h" QString Person::name() const { @@ -73,16 +69,3 @@ void Person::setShoeSize(int s) { m_shoeSize = s; } - - -Boy::Boy(QObject * parent) -: Person(parent) -{ -} - - -Girl::Girl(QObject * parent) -: Person(parent) -{ -} - diff --git a/examples/qml/referenceexamples/default/person.h b/examples/qml/referenceexamples/default/person.h index 361a89c599..0b2e280747 100644 --- a/examples/qml/referenceexamples/default/person.h +++ b/examples/qml/referenceexamples/default/person.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. @@ -47,6 +47,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ + #ifndef PERSON_H #define PERSON_H @@ -60,7 +61,7 @@ class Person : public QObject Q_PROPERTY(int shoeSize READ shoeSize WRITE setShoeSize) QML_ANONYMOUS public: - Person(QObject *parent = nullptr); + using QObject::QObject; QString name() const; void setName(const QString &); @@ -69,7 +70,7 @@ public: void setShoeSize(int); private: QString m_name; - int m_shoeSize; + int m_shoeSize = 0; }; class Boy : public Person @@ -77,7 +78,7 @@ class Boy : public Person Q_OBJECT QML_ELEMENT public: - Boy(QObject * parent = nullptr); + using Person::Person; }; class Girl : public Person @@ -85,7 +86,7 @@ class Girl : public Person Q_OBJECT QML_ELEMENT public: - Girl(QObject * parent = nullptr); + using Person::Person; }; #endif // PERSON_H diff --git a/examples/qml/referenceexamples/extended/CMakeLists.txt b/examples/qml/referenceexamples/extended/CMakeLists.txt index 6843b39d38..ea659e5f71 100644 --- a/examples/qml/referenceexamples/extended/CMakeLists.txt +++ b/examples/qml/referenceexamples/extended/CMakeLists.txt @@ -1,6 +1,6 @@ # Generated from extended.pro. -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(extended LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) @@ -35,17 +35,11 @@ target_link_libraries(extended PUBLIC Qt::Widgets ) - -# Resources: -set(extended_resource_files - "example.qml" -) - -qt6_add_resources(extended "extended" - PREFIX - "/" - FILES - ${extended_resource_files} +qt_add_qml_module(extended + URI People + VERSION 1.0 + QML_FILES example.qml + NO_RESOURCE_TARGET_PATH ) install(TARGETS extended @@ -53,10 +47,3 @@ install(TARGETS extended BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) - -set_target_properties(extended PROPERTIES - QT_QML_MODULE_VERSION 1.0 - QT_QML_MODULE_URI People -) - -qt6_qml_type_registration(extended) diff --git a/examples/qml/referenceexamples/grouped/CMakeLists.txt b/examples/qml/referenceexamples/grouped/CMakeLists.txt index 19dd60358b..f7a31d9c1e 100644 --- a/examples/qml/referenceexamples/grouped/CMakeLists.txt +++ b/examples/qml/referenceexamples/grouped/CMakeLists.txt @@ -1,6 +1,6 @@ # Generated from grouped.pro. -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(grouped LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) @@ -34,17 +34,11 @@ target_link_libraries(grouped PUBLIC Qt::Qml ) - -# Resources: -set(grouped_resource_files - "example.qml" -) - -qt6_add_resources(grouped "grouped" - PREFIX - "/" - FILES - ${grouped_resource_files} +qt_add_qml_module(grouped + URI People + VERSION 1.0 + QML_FILES example.qml + NO_RESOURCE_TARGET_PATH ) install(TARGETS grouped @@ -52,10 +46,3 @@ install(TARGETS grouped BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) - -set_target_properties(grouped PROPERTIES - QT_QML_MODULE_VERSION 1.0 - QT_QML_MODULE_URI People -) - -qt6_qml_type_registration(grouped) diff --git a/examples/qml/referenceexamples/grouped/birthdayparty.cpp b/examples/qml/referenceexamples/grouped/birthdayparty.cpp index 81db8ab1b8..269f45e02c 100644 --- a/examples/qml/referenceexamples/grouped/birthdayparty.cpp +++ b/examples/qml/referenceexamples/grouped/birthdayparty.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. @@ -47,12 +47,8 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ -#include "birthdayparty.h" -BirthdayParty::BirthdayParty(QObject *parent) -: QObject(parent), m_host(nullptr) -{ -} +#include "birthdayparty.h" Person *BirthdayParty::host() const { @@ -69,13 +65,12 @@ QQmlListProperty<Person> BirthdayParty::guests() return {this, &m_guests}; } -int BirthdayParty::guestCount() const +qsizetype BirthdayParty::guestCount() const { return m_guests.count(); } -Person *BirthdayParty::guest(int index) const +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 index f6834dad89..a8e0964365 100644 --- a/examples/qml/referenceexamples/grouped/birthdayparty.h +++ b/examples/qml/referenceexamples/grouped/birthdayparty.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. @@ -47,6 +47,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ + #ifndef BIRTHDAYPARTY_H #define BIRTHDAYPARTY_H @@ -62,14 +63,14 @@ class BirthdayParty : public QObject Q_CLASSINFO("DefaultProperty", "guests") QML_ELEMENT public: - BirthdayParty(QObject *parent = nullptr); + using QObject::QObject; Person *host() const; void setHost(Person *); QQmlListProperty<Person> guests(); - int guestCount() const; - Person *guest(int) const; + qsizetype guestCount() const; + Person *guest(qsizetype) const; private: Person *m_host; diff --git a/examples/qml/referenceexamples/grouped/main.cpp b/examples/qml/referenceexamples/grouped/main.cpp index 63dbe988a4..6d4ec517cc 100644 --- a/examples/qml/referenceexamples/grouped/main.cpp +++ b/examples/qml/referenceexamples/grouped/main.cpp @@ -63,23 +63,23 @@ int main(int argc, char ** argv) auto *party = qobject_cast<BirthdayParty *>(component.create()); if (party && party->host()) { - qWarning() << party->host()->name() << "is having a birthday!"; + qInfo() << party->host()->name() << "is having a birthday!"; if (qobject_cast<Boy *>(party->host())) - qWarning() << "He is inviting:"; + qInfo() << "He is inviting:"; else - qWarning() << "She is inviting:"; + qInfo() << "She is inviting:"; Person *bestShoe = nullptr; - for (int ii = 0; ii < party->guestCount(); ++ii) { + for (qsizetype ii = 0; ii < party->guestCount(); ++ii) { Person *guest = party->guest(ii); - qWarning() << " " << guest->name(); + qInfo() << " " << guest->name(); if (!bestShoe || bestShoe->shoe()->price() < guest->shoe()->price()) bestShoe = guest; } if (bestShoe) - qWarning() << bestShoe->name() << "is wearing the best shoes!"; + qInfo() << bestShoe->name() << "is wearing the best shoes!"; return EXIT_SUCCESS; } diff --git a/examples/qml/referenceexamples/grouped/person.cpp b/examples/qml/referenceexamples/grouped/person.cpp index 0603644108..4e52da76c8 100644 --- a/examples/qml/referenceexamples/grouped/person.cpp +++ b/examples/qml/referenceexamples/grouped/person.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. @@ -47,12 +47,8 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ -#include "person.h" -ShoeDescription::ShoeDescription(QObject *parent) -: QObject(parent), m_size(0), m_price(0) -{ -} +#include "person.h" int ShoeDescription::size() const { @@ -94,11 +90,6 @@ void ShoeDescription::setPrice(qreal p) m_price = p; } -Person::Person(QObject *parent) -: QObject(parent) -{ -} - QString Person::name() const { return m_name; @@ -113,16 +104,3 @@ ShoeDescription *Person::shoe() { return &m_shoe; } - - -Boy::Boy(QObject * parent) -: Person(parent) -{ -} - - -Girl::Girl(QObject * parent) -: Person(parent) -{ -} - diff --git a/examples/qml/referenceexamples/grouped/person.h b/examples/qml/referenceexamples/grouped/person.h index df507c7386..ed77f8c4d8 100644 --- a/examples/qml/referenceexamples/grouped/person.h +++ b/examples/qml/referenceexamples/grouped/person.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. @@ -47,6 +47,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ + #ifndef PERSON_H #define PERSON_H @@ -63,7 +64,7 @@ class ShoeDescription : public QObject Q_PROPERTY(qreal price READ price WRITE setPrice) QML_ANONYMOUS public: - ShoeDescription(QObject *parent = nullptr); + using QObject::QObject; int size() const; void setSize(int); @@ -76,11 +77,12 @@ public: qreal price() const; void setPrice(qreal); + private: - int m_size; + int m_size = 0; QColor m_color; QString m_brand; - qreal m_price; + qreal m_price = 0; }; class Person : public QObject @@ -92,7 +94,7 @@ class Person : public QObject // ![1] QML_ANONYMOUS public: - Person(QObject *parent = nullptr); + using QObject::QObject; QString name() const; void setName(const QString &); @@ -108,7 +110,7 @@ class Boy : public Person Q_OBJECT QML_ELEMENT public: - Boy(QObject * parent = nullptr); + using Person::Person; }; class Girl : public Person @@ -116,7 +118,7 @@ class Girl : public Person Q_OBJECT QML_ELEMENT public: - Girl(QObject * parent = nullptr); + using Person::Person; }; #endif // PERSON_H diff --git a/examples/qml/referenceexamples/methods/CMakeLists.txt b/examples/qml/referenceexamples/methods/CMakeLists.txt index 886928e10e..304aa3082a 100644 --- a/examples/qml/referenceexamples/methods/CMakeLists.txt +++ b/examples/qml/referenceexamples/methods/CMakeLists.txt @@ -1,6 +1,6 @@ # Generated from methods.pro. -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(methods LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) @@ -32,17 +32,11 @@ target_link_libraries(methods PUBLIC Qt::Qml ) - -# Resources: -set(methods_resource_files - "example.qml" -) - -qt6_add_resources(methods "methods" - PREFIX - "/" - FILES - ${methods_resource_files} +qt_add_qml_module(methods + URI People + VERSION 1.0 + QML_FILES example.qml + NO_RESOURCE_TARGET_PATH ) install(TARGETS methods @@ -50,10 +44,3 @@ install(TARGETS methods BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) - -set_target_properties(methods PROPERTIES - QT_QML_MODULE_VERSION 1.0 - QT_QML_MODULE_URI People -) - -qt6_qml_type_registration(methods) diff --git a/examples/qml/referenceexamples/methods/birthdayparty.cpp b/examples/qml/referenceexamples/methods/birthdayparty.cpp index 4b30d31aeb..1308a09b72 100644 --- a/examples/qml/referenceexamples/methods/birthdayparty.cpp +++ b/examples/qml/referenceexamples/methods/birthdayparty.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. @@ -47,12 +47,8 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ -#include "birthdayparty.h" -BirthdayParty::BirthdayParty(QObject *parent) -: QObject(parent), m_host(nullptr) -{ -} +#include "birthdayparty.h" // ![0] Person *BirthdayParty::host() const @@ -70,12 +66,12 @@ QQmlListProperty<Person> BirthdayParty::guests() return {this, &m_guests}; } -int BirthdayParty::guestCount() const +qsizetype BirthdayParty::guestCount() const { return m_guests.count(); } -Person *BirthdayParty::guest(int index) const +Person *BirthdayParty::guest(qsizetype index) const { return m_guests.at(index); } diff --git a/examples/qml/referenceexamples/methods/birthdayparty.h b/examples/qml/referenceexamples/methods/birthdayparty.h index 5c2f3c9def..b43308ac8f 100644 --- a/examples/qml/referenceexamples/methods/birthdayparty.h +++ b/examples/qml/referenceexamples/methods/birthdayparty.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. @@ -47,6 +47,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ + #ifndef BIRTHDAYPARTY_H #define BIRTHDAYPARTY_H @@ -61,21 +62,21 @@ class BirthdayParty : public QObject Q_PROPERTY(QQmlListProperty<Person> guests READ guests) QML_ELEMENT public: - BirthdayParty(QObject *parent = nullptr); + using QObject::QObject; Person *host() const; void setHost(Person *); QQmlListProperty<Person> guests(); - int guestCount() const; - Person *guest(int) const; + qsizetype guestCount() const; + Person *guest(qsizetype) const; // ![0] Q_INVOKABLE void invite(const QString &name); // ![0] private: - Person *m_host; + Person *m_host = nullptr; QList<Person *> m_guests; }; diff --git a/examples/qml/referenceexamples/methods/main.cpp b/examples/qml/referenceexamples/methods/main.cpp index e30e1d9fb1..32eb4831cc 100644 --- a/examples/qml/referenceexamples/methods/main.cpp +++ b/examples/qml/referenceexamples/methods/main.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. @@ -47,6 +47,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ + #include <QCoreApplication> #include <QQmlEngine> #include <QQmlComponent> @@ -63,10 +64,10 @@ int main(int argc, char ** argv) auto *party = qobject_cast<BirthdayParty *>(component.create()); if (party && party->host()) { - qWarning() << party->host()->name() << "is having a birthday!"; - qWarning() << "They are inviting:"; - for (int ii = 0; ii < party->guestCount(); ++ii) - qWarning() << " " << party->guest(ii)->name(); + qInfo() << party->host()->name() << "is having a birthday!" + << "\nThey are inviting:"; + for (qsizetype ii = 0; ii < party->guestCount(); ++ii) + qInfo() << " " << party->guest(ii)->name(); return EXIT_SUCCESS; } diff --git a/examples/qml/referenceexamples/methods/person.cpp b/examples/qml/referenceexamples/methods/person.cpp index 7712363ebf..e2847a2682 100644 --- a/examples/qml/referenceexamples/methods/person.cpp +++ b/examples/qml/referenceexamples/methods/person.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. @@ -47,12 +47,8 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ -#include "person.h" -Person::Person(QObject *parent) -: QObject(parent), m_shoeSize(0) -{ -} +#include "person.h" QString Person::name() const { @@ -73,4 +69,3 @@ void Person::setShoeSize(int s) { m_shoeSize = s; } - diff --git a/examples/qml/referenceexamples/methods/person.h b/examples/qml/referenceexamples/methods/person.h index 2407fbb1b9..0849d1ee8c 100644 --- a/examples/qml/referenceexamples/methods/person.h +++ b/examples/qml/referenceexamples/methods/person.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. @@ -47,6 +47,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ + #ifndef PERSON_H #define PERSON_H @@ -60,16 +61,17 @@ class Person : public QObject Q_PROPERTY(int shoeSize READ shoeSize WRITE setShoeSize) QML_ELEMENT public: - Person(QObject *parent = nullptr); + using QObject::QObject; QString name() const; void setName(const QString &); int shoeSize() const; void setShoeSize(int); + private: QString m_name; - int m_shoeSize; + int m_shoeSize = 0; }; #endif // PERSON_H diff --git a/examples/qml/referenceexamples/properties/CMakeLists.txt b/examples/qml/referenceexamples/properties/CMakeLists.txt index 1d4daf56d6..11f70f337f 100644 --- a/examples/qml/referenceexamples/properties/CMakeLists.txt +++ b/examples/qml/referenceexamples/properties/CMakeLists.txt @@ -1,6 +1,6 @@ # Generated from properties.pro. -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(properties LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) @@ -32,17 +32,11 @@ target_link_libraries(properties PUBLIC Qt::Qml ) - -# Resources: -set(properties_resource_files - "example.qml" -) - -qt6_add_resources(properties "properties" - PREFIX - "/" - FILES - ${properties_resource_files} +qt_add_qml_module(properties + URI People + VERSION 1.0 + QML_FILES example.qml + NO_RESOURCE_TARGET_PATH ) install(TARGETS properties @@ -50,10 +44,3 @@ install(TARGETS properties BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) - -set_target_properties(properties PROPERTIES - QT_QML_MODULE_VERSION 1.0 - QT_QML_MODULE_URI People -) - -qt6_qml_type_registration(properties) diff --git a/examples/qml/referenceexamples/properties/birthdayparty.cpp b/examples/qml/referenceexamples/properties/birthdayparty.cpp index 2dc9bd803d..aca626db74 100644 --- a/examples/qml/referenceexamples/properties/birthdayparty.cpp +++ b/examples/qml/referenceexamples/properties/birthdayparty.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. @@ -47,12 +47,8 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ -#include "birthdayparty.h" -BirthdayParty::BirthdayParty(QObject *parent) -: QObject(parent), m_host(nullptr) -{ -} +#include "birthdayparty.h" // ![0] Person *BirthdayParty::host() const @@ -76,11 +72,11 @@ QQmlListProperty<Person> BirthdayParty::guests() &BirthdayParty::removeLastGuest}; } -void BirthdayParty::appendGuest(Person* p) { +void BirthdayParty::appendGuest(Person *p) +{ m_guests.append(p); } - qsizetype BirthdayParty::guestCount() const { return m_guests.count(); @@ -107,12 +103,14 @@ void BirthdayParty::removeLastGuest() // ![0] -void BirthdayParty::appendGuest(QQmlListProperty<Person>* list, Person* p) { - reinterpret_cast< BirthdayParty* >(list->data)->appendGuest(p); +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::clearGuests(QQmlListProperty<Person>* list) +{ + reinterpret_cast< BirthdayParty *>(list->data)->clearGuests(); } void BirthdayParty::replaceGuest(QQmlListProperty<Person> *list, qsizetype i, Person *p) @@ -125,10 +123,12 @@ void BirthdayParty::removeLastGuest(QQmlListProperty<Person> *list) reinterpret_cast< BirthdayParty* >(list->data)->removeLastGuest(); } -Person* BirthdayParty::guest(QQmlListProperty<Person>* list, qsizetype i) { +Person* BirthdayParty::guest(QQmlListProperty<Person> *list, qsizetype i) +{ return reinterpret_cast< BirthdayParty* >(list->data)->guest(i); } -qsizetype BirthdayParty::guestCount(QQmlListProperty<Person>* list) { +qsizetype BirthdayParty::guestCount(QQmlListProperty<Person> *list) +{ return reinterpret_cast< BirthdayParty* >(list->data)->guestCount(); } diff --git a/examples/qml/referenceexamples/properties/birthdayparty.h b/examples/qml/referenceexamples/properties/birthdayparty.h index 7e1668add3..278c011d11 100644 --- a/examples/qml/referenceexamples/properties/birthdayparty.h +++ b/examples/qml/referenceexamples/properties/birthdayparty.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. @@ -47,6 +47,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ + #ifndef BIRTHDAYPARTY_H #define BIRTHDAYPARTY_H @@ -69,28 +70,28 @@ class BirthdayParty : public QObject // ![3] QML_ELEMENT public: - BirthdayParty(QObject *parent = nullptr); + using QObject::QObject; Person *host() const; void setHost(Person *); QQmlListProperty<Person> guests(); - void appendGuest(Person*); + void appendGuest(Person *); qsizetype guestCount() const; Person *guest(qsizetype) const; void clearGuests(); - void replaceGuest(qsizetype, Person*); + void replaceGuest(qsizetype, Person *); void removeLastGuest(); 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>*); + 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; + Person *m_host = nullptr; QList<Person *> m_guests; }; // ![3] diff --git a/examples/qml/referenceexamples/properties/main.cpp b/examples/qml/referenceexamples/properties/main.cpp index e30e1d9fb1..cd71497002 100644 --- a/examples/qml/referenceexamples/properties/main.cpp +++ b/examples/qml/referenceexamples/properties/main.cpp @@ -63,10 +63,10 @@ int main(int argc, char ** argv) auto *party = qobject_cast<BirthdayParty *>(component.create()); if (party && party->host()) { - qWarning() << party->host()->name() << "is having a birthday!"; - qWarning() << "They are inviting:"; - for (int ii = 0; ii < party->guestCount(); ++ii) - qWarning() << " " << party->guest(ii)->name(); + 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/referenceexamples/properties/person.cpp b/examples/qml/referenceexamples/properties/person.cpp index 7712363ebf..e2847a2682 100644 --- a/examples/qml/referenceexamples/properties/person.cpp +++ b/examples/qml/referenceexamples/properties/person.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. @@ -47,12 +47,8 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ -#include "person.h" -Person::Person(QObject *parent) -: QObject(parent), m_shoeSize(0) -{ -} +#include "person.h" QString Person::name() const { @@ -73,4 +69,3 @@ void Person::setShoeSize(int s) { m_shoeSize = s; } - diff --git a/examples/qml/referenceexamples/properties/person.h b/examples/qml/referenceexamples/properties/person.h index 2407fbb1b9..0849d1ee8c 100644 --- a/examples/qml/referenceexamples/properties/person.h +++ b/examples/qml/referenceexamples/properties/person.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. @@ -47,6 +47,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ + #ifndef PERSON_H #define PERSON_H @@ -60,16 +61,17 @@ class Person : public QObject Q_PROPERTY(int shoeSize READ shoeSize WRITE setShoeSize) QML_ELEMENT public: - Person(QObject *parent = nullptr); + using QObject::QObject; QString name() const; void setName(const QString &); int shoeSize() const; void setShoeSize(int); + private: QString m_name; - int m_shoeSize; + int m_shoeSize = 0; }; #endif // PERSON_H diff --git a/examples/qml/referenceexamples/signal/CMakeLists.txt b/examples/qml/referenceexamples/signal/CMakeLists.txt index b309efc576..23e494f7c9 100644 --- a/examples/qml/referenceexamples/signal/CMakeLists.txt +++ b/examples/qml/referenceexamples/signal/CMakeLists.txt @@ -1,6 +1,6 @@ # Generated from signal.pro. -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(signal LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) @@ -34,17 +34,11 @@ target_link_libraries(signal PUBLIC Qt::Qml ) - -# Resources: -set(signal_resource_files - "example.qml" -) - -qt6_add_resources(signal "signal" - PREFIX - "/" - FILES - ${signal_resource_files} +qt_add_qml_module(signal + URI People + VERSION 1.0 + QML_FILES example.qml + NO_RESOURCE_TARGET_PATH ) install(TARGETS signal @@ -52,10 +46,3 @@ install(TARGETS signal BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) - -set_target_properties(signal PROPERTIES - QT_QML_MODULE_VERSION 1.0 - QT_QML_MODULE_URI People -) - -qt6_qml_type_registration(signal) diff --git a/examples/qml/referenceexamples/signal/birthdayparty.cpp b/examples/qml/referenceexamples/signal/birthdayparty.cpp index 215c09782a..27498c9cc9 100644 --- a/examples/qml/referenceexamples/signal/birthdayparty.cpp +++ b/examples/qml/referenceexamples/signal/birthdayparty.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. @@ -47,16 +47,12 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ -#include "birthdayparty.h" -BirthdayPartyAttached::BirthdayPartyAttached(QObject *object) -: QObject(object) -{ -} +#include "birthdayparty.h" QDate BirthdayPartyAttached::rsvp() const { - return m_rsvp; + return m_rsvp; } void BirthdayPartyAttached::setRsvp(QDate d) @@ -64,12 +60,6 @@ void BirthdayPartyAttached::setRsvp(QDate d) m_rsvp = d; } - -BirthdayParty::BirthdayParty(QObject *parent) -: QObject(parent), m_host(nullptr) -{ -} - Person *BirthdayParty::host() const { return m_host; @@ -85,12 +75,12 @@ QQmlListProperty<Person> BirthdayParty::guests() return {this, &m_guests}; } -int BirthdayParty::guestCount() const +qsizetype BirthdayParty::guestCount() const { return m_guests.count(); } -Person *BirthdayParty::guest(int index) const +Person *BirthdayParty::guest(qsizetype index) const { return m_guests.at(index); } diff --git a/examples/qml/referenceexamples/signal/birthdayparty.h b/examples/qml/referenceexamples/signal/birthdayparty.h index 6d7e022df0..c4a4da5dfb 100644 --- a/examples/qml/referenceexamples/signal/birthdayparty.h +++ b/examples/qml/referenceexamples/signal/birthdayparty.h @@ -61,7 +61,7 @@ class BirthdayPartyAttached : public QObject Q_PROPERTY(QDate rsvp READ rsvp WRITE setRsvp) QML_ANONYMOUS public: - BirthdayPartyAttached(QObject *object); + using QObject::QObject; QDate rsvp() const; void setRsvp(QDate); @@ -79,14 +79,14 @@ class BirthdayParty : public QObject QML_ELEMENT QML_ATTACHED(BirthdayPartyAttached) public: - BirthdayParty(QObject *parent = nullptr); + using QObject::QObject; Person *host() const; void setHost(Person *); QQmlListProperty<Person> guests(); - int guestCount() const; - Person *guest(int) const; + qsizetype guestCount() const; + Person *guest(qsizetype) const; static BirthdayPartyAttached *qmlAttachedProperties(QObject *); @@ -97,7 +97,7 @@ signals: // ![0] private: - Person *m_host; + Person *m_host = nullptr; QList<Person *> m_guests; }; diff --git a/examples/qml/referenceexamples/signal/main.cpp b/examples/qml/referenceexamples/signal/main.cpp index 7ef3595a8c..d0b060d8e6 100644 --- a/examples/qml/referenceexamples/signal/main.cpp +++ b/examples/qml/referenceexamples/signal/main.cpp @@ -63,14 +63,14 @@ int main(int argc, char ** argv) auto *party = qobject_cast<BirthdayParty *>(component.create()); if (party && party->host()) { - qWarning() << party->host()->name() << "is having a birthday!"; + qInfo() << party->host()->name() << "is having a birthday!"; if (qobject_cast<Boy *>(party->host())) - qWarning() << "He is inviting:"; + qInfo() << "He is inviting:"; else - qWarning() << "She is inviting:"; + qInfo() << "She is inviting:"; - for (int ii = 0; ii < party->guestCount(); ++ii) { + for (qsizetype ii = 0; ii < party->guestCount(); ++ii) { Person *guest = party->guest(ii); QDate rsvpDate; @@ -80,9 +80,9 @@ int main(int argc, char ** argv) rsvpDate = attached->property("rsvp").toDate(); if (rsvpDate.isNull()) - qWarning() << " " << guest->name() << "RSVP date: Hasn't RSVP'd"; + qInfo() << " " << guest->name() << "RSVP date: Hasn't RSVP'd"; else - qWarning() << " " << guest->name() << "RSVP date:" << qPrintable(rsvpDate.toString()); + qInfo() << " " << guest->name() << "RSVP date:" << rsvpDate.toString(); } party->startParty(); diff --git a/examples/qml/referenceexamples/signal/person.cpp b/examples/qml/referenceexamples/signal/person.cpp index 0603644108..4e52da76c8 100644 --- a/examples/qml/referenceexamples/signal/person.cpp +++ b/examples/qml/referenceexamples/signal/person.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. @@ -47,12 +47,8 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ -#include "person.h" -ShoeDescription::ShoeDescription(QObject *parent) -: QObject(parent), m_size(0), m_price(0) -{ -} +#include "person.h" int ShoeDescription::size() const { @@ -94,11 +90,6 @@ void ShoeDescription::setPrice(qreal p) m_price = p; } -Person::Person(QObject *parent) -: QObject(parent) -{ -} - QString Person::name() const { return m_name; @@ -113,16 +104,3 @@ ShoeDescription *Person::shoe() { return &m_shoe; } - - -Boy::Boy(QObject * parent) -: Person(parent) -{ -} - - -Girl::Girl(QObject * parent) -: Person(parent) -{ -} - diff --git a/examples/qml/referenceexamples/signal/person.h b/examples/qml/referenceexamples/signal/person.h index 7283f39f61..ddd3baa5f2 100644 --- a/examples/qml/referenceexamples/signal/person.h +++ b/examples/qml/referenceexamples/signal/person.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. @@ -47,6 +47,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ + #ifndef PERSON_H #define PERSON_H @@ -63,7 +64,7 @@ class ShoeDescription : public QObject Q_PROPERTY(qreal price READ price WRITE setPrice) QML_ANONYMOUS public: - ShoeDescription(QObject *parent = nullptr); + using QObject::QObject; int size() const; void setSize(int); @@ -76,11 +77,12 @@ public: qreal price() const; void setPrice(qreal); + private: - int m_size; + int m_size = 0; QColor m_color; QString m_brand; - qreal m_price; + qreal m_price = 0; }; class Person : public QObject @@ -90,7 +92,7 @@ class Person : public QObject Q_PROPERTY(ShoeDescription *shoe READ shoe) QML_ANONYMOUS public: - Person(QObject *parent = nullptr); + using QObject::QObject; QString name() const; void setName(const QString &); @@ -106,7 +108,7 @@ class Boy : public Person Q_OBJECT QML_ELEMENT public: - Boy(QObject * parent = nullptr); + using Person::Person; }; class Girl : public Person @@ -114,7 +116,7 @@ class Girl : public Person Q_OBJECT QML_ELEMENT public: - Girl(QObject * parent = nullptr); + using Person::Person; }; #endif // PERSON_H diff --git a/examples/qml/referenceexamples/valuesource/CMakeLists.txt b/examples/qml/referenceexamples/valuesource/CMakeLists.txt index 9bdf9fc309..3e997bb8f8 100644 --- a/examples/qml/referenceexamples/valuesource/CMakeLists.txt +++ b/examples/qml/referenceexamples/valuesource/CMakeLists.txt @@ -1,6 +1,6 @@ # Generated from valuesource.pro. -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(valuesource LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) @@ -35,17 +35,11 @@ target_link_libraries(valuesource PUBLIC Qt::Qml ) - -# Resources: -set(valuesource_resource_files - "example.qml" -) - -qt6_add_resources(valuesource "valuesource" - PREFIX - "/" - FILES - ${valuesource_resource_files} +qt_add_qml_module(valuesource + URI People + VERSION 1.0 + QML_FILES example.qml + NO_RESOURCE_TARGET_PATH ) install(TARGETS valuesource @@ -53,10 +47,3 @@ install(TARGETS valuesource BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) - -set_target_properties(valuesource PROPERTIES - QT_QML_MODULE_VERSION 1.0 - QT_QML_MODULE_URI People -) - -qt6_qml_type_registration(valuesource) diff --git a/examples/qml/referenceexamples/valuesource/birthdayparty.cpp b/examples/qml/referenceexamples/valuesource/birthdayparty.cpp index 7ad11066cb..ced34c0cbb 100644 --- a/examples/qml/referenceexamples/valuesource/birthdayparty.cpp +++ b/examples/qml/referenceexamples/valuesource/birthdayparty.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. @@ -47,12 +47,8 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ -#include "birthdayparty.h" -BirthdayPartyAttached::BirthdayPartyAttached(QObject *object) -: QObject(object) -{ -} +#include "birthdayparty.h" QDate BirthdayPartyAttached::rsvp() const { @@ -64,12 +60,6 @@ void BirthdayPartyAttached::setRsvp(QDate d) m_rsvp = d; } - -BirthdayParty::BirthdayParty(QObject *parent) -: QObject(parent), m_host(nullptr) -{ -} - Person *BirthdayParty::host() const { return m_host; @@ -85,12 +75,12 @@ QQmlListProperty<Person> BirthdayParty::guests() return {this, &m_guests}; } -int BirthdayParty::guestCount() const +qsizetype BirthdayParty::guestCount() const { return m_guests.count(); } -Person *BirthdayParty::guest(int index) const +Person *BirthdayParty::guest(qsizetype index) const { return m_guests.at(index); } @@ -108,11 +98,10 @@ QString BirthdayParty::announcement() const void BirthdayParty::setAnnouncement(const QString &speak) { - qWarning() << qPrintable(speak); + qInfo().noquote() << speak; } BirthdayPartyAttached *BirthdayParty::qmlAttachedProperties(QObject *object) { return new BirthdayPartyAttached(object); } - diff --git a/examples/qml/referenceexamples/valuesource/birthdayparty.h b/examples/qml/referenceexamples/valuesource/birthdayparty.h index abd6363571..4c661499ce 100644 --- a/examples/qml/referenceexamples/valuesource/birthdayparty.h +++ b/examples/qml/referenceexamples/valuesource/birthdayparty.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. @@ -47,6 +47,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ + #ifndef BIRTHDAYPARTY_H #define BIRTHDAYPARTY_H @@ -62,7 +63,7 @@ class BirthdayPartyAttached : public QObject Q_PROPERTY(QDate rsvp READ rsvp WRITE setRsvp) QML_ANONYMOUS public: - BirthdayPartyAttached(QObject *object); + using QObject::QObject; QDate rsvp() const; void setRsvp(QDate); @@ -83,14 +84,14 @@ class BirthdayParty : public QObject QML_ELEMENT QML_ATTACHED(BirthdayPartyAttached) public: - BirthdayParty(QObject *parent = nullptr); + using QObject::QObject; Person *host() const; void setHost(Person *); QQmlListProperty<Person> guests(); - int guestCount() const; - Person *guest(int) const; + qsizetype guestCount() const; + Person *guest(qsizetype) const; QString announcement() const; void setAnnouncement(const QString &); @@ -98,11 +99,12 @@ public: static BirthdayPartyAttached *qmlAttachedProperties(QObject *); void startParty(); + signals: void partyStarted(QTime time); private: - Person *m_host; + Person *m_host = nullptr; QList<Person *> m_guests; }; diff --git a/examples/qml/referenceexamples/valuesource/happybirthdaysong.cpp b/examples/qml/referenceexamples/valuesource/happybirthdaysong.cpp index da09d3d7ba..635a50ef12 100644 --- a/examples/qml/referenceexamples/valuesource/happybirthdaysong.cpp +++ b/examples/qml/referenceexamples/valuesource/happybirthdaysong.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. @@ -47,13 +47,13 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ + #include "happybirthdaysong.h" #include <QTimer> -HappyBirthdaySong::HappyBirthdaySong(QObject *parent) -: QObject(parent), m_line(-1) +HappyBirthdaySong::HappyBirthdaySong(QObject *parent) : + QObject(parent) { - setName(QString()); auto *timer = new QTimer(this); QObject::connect(timer, &QTimer::timeout, this, &HappyBirthdaySong::advance); timer->start(1000); diff --git a/examples/qml/referenceexamples/valuesource/happybirthdaysong.h b/examples/qml/referenceexamples/valuesource/happybirthdaysong.h index 2600208968..146e336487 100644 --- a/examples/qml/referenceexamples/valuesource/happybirthdaysong.h +++ b/examples/qml/referenceexamples/valuesource/happybirthdaysong.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. @@ -47,6 +47,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ + #ifndef HAPPYBIRTHDAYSONG_H #define HAPPYBIRTHDAYSONG_H @@ -66,7 +67,7 @@ class HappyBirthdaySong : public QObject, public QQmlPropertyValueSource // ![1] QML_ELEMENT public: - HappyBirthdaySong(QObject *parent = nullptr); + explicit HappyBirthdaySong(QObject *parent = nullptr); void setTarget(const QQmlProperty &) override; // ![1] @@ -78,7 +79,7 @@ private slots: void advance(); private: - int m_line; + qsizetype m_line = -1; QStringList m_lyrics; QQmlProperty m_target; QString m_name; diff --git a/examples/qml/referenceexamples/valuesource/main.cpp b/examples/qml/referenceexamples/valuesource/main.cpp index 2e9995fcd8..a100497659 100644 --- a/examples/qml/referenceexamples/valuesource/main.cpp +++ b/examples/qml/referenceexamples/valuesource/main.cpp @@ -64,14 +64,14 @@ int main(int argc, char ** argv) auto *party = qobject_cast<BirthdayParty *>(component.create()); if (party && party->host()) { - qWarning() << party->host()->name() << "is having a birthday!"; + qInfo() << party->host()->name() << "is having a birthday!"; if (qobject_cast<Boy *>(party->host())) - qWarning() << "He is inviting:"; + qInfo() << "He is inviting:"; else - qWarning() << "She is inviting:"; + qInfo() << "She is inviting:"; - for (int ii = 0; ii < party->guestCount(); ++ii) { + for (qsizetype ii = 0; ii < party->guestCount(); ++ii) { Person *guest = party->guest(ii); QDate rsvpDate; @@ -81,9 +81,9 @@ int main(int argc, char ** argv) rsvpDate = attached->property("rsvp").toDate(); if (rsvpDate.isNull()) - qWarning() << " " << guest->name() << "RSVP date: Hasn't RSVP'd"; + qInfo() << " " << guest->name() << "RSVP date: Hasn't RSVP'd"; else - qWarning() << " " << guest->name() << "RSVP date:" << qPrintable(rsvpDate.toString()); + qInfo() << " " << guest->name() << "RSVP date:" << rsvpDate.toString(); } party->startParty(); diff --git a/examples/qml/referenceexamples/valuesource/person.cpp b/examples/qml/referenceexamples/valuesource/person.cpp index 0603644108..4e52da76c8 100644 --- a/examples/qml/referenceexamples/valuesource/person.cpp +++ b/examples/qml/referenceexamples/valuesource/person.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. @@ -47,12 +47,8 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ -#include "person.h" -ShoeDescription::ShoeDescription(QObject *parent) -: QObject(parent), m_size(0), m_price(0) -{ -} +#include "person.h" int ShoeDescription::size() const { @@ -94,11 +90,6 @@ void ShoeDescription::setPrice(qreal p) m_price = p; } -Person::Person(QObject *parent) -: QObject(parent) -{ -} - QString Person::name() const { return m_name; @@ -113,16 +104,3 @@ ShoeDescription *Person::shoe() { return &m_shoe; } - - -Boy::Boy(QObject * parent) -: Person(parent) -{ -} - - -Girl::Girl(QObject * parent) -: Person(parent) -{ -} - diff --git a/examples/qml/referenceexamples/valuesource/person.h b/examples/qml/referenceexamples/valuesource/person.h index 7283f39f61..ed77f8c4d8 100644 --- a/examples/qml/referenceexamples/valuesource/person.h +++ b/examples/qml/referenceexamples/valuesource/person.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. @@ -47,6 +47,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ + #ifndef PERSON_H #define PERSON_H @@ -63,7 +64,7 @@ class ShoeDescription : public QObject Q_PROPERTY(qreal price READ price WRITE setPrice) QML_ANONYMOUS public: - ShoeDescription(QObject *parent = nullptr); + using QObject::QObject; int size() const; void setSize(int); @@ -76,21 +77,24 @@ public: qreal price() const; void setPrice(qreal); + private: - int m_size; + int m_size = 0; QColor m_color; QString m_brand; - qreal m_price; + 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: - Person(QObject *parent = nullptr); + using QObject::QObject; QString name() const; void setName(const QString &); @@ -106,7 +110,7 @@ class Boy : public Person Q_OBJECT QML_ELEMENT public: - Boy(QObject * parent = nullptr); + using Person::Person; }; class Girl : public Person @@ -114,7 +118,7 @@ class Girl : public Person Q_OBJECT QML_ELEMENT public: - Girl(QObject * parent = nullptr); + using Person::Person; }; #endif // PERSON_H diff --git a/examples/qml/shell/CMakeLists.txt b/examples/qml/shell/CMakeLists.txt index 6c986b7778..c048159fc4 100644 --- a/examples/qml/shell/CMakeLists.txt +++ b/examples/qml/shell/CMakeLists.txt @@ -1,6 +1,6 @@ # Generated from shell.pro. -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(shell LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) diff --git a/examples/qml/tutorials/extending-qml/.prev_CMakeLists.txt b/examples/qml/tutorials/extending-qml/.prev_CMakeLists.txt deleted file mode 100644 index 8e41f3d77d..0000000000 --- a/examples/qml/tutorials/extending-qml/.prev_CMakeLists.txt +++ /dev/null @@ -1,8 +0,0 @@ -# Generated from extending-qml.pro. - -add_subdirectory(chapter1-basics) -add_subdirectory(chapter2-methods) -add_subdirectory(chapter3-bindings) -add_subdirectory(chapter4-customPropertyTypes) -add_subdirectory(chapter5-listproperties) -add_subdirectory(chapter6-plugins) diff --git a/examples/qml/tutorials/extending-qml/chapter1-basics/CMakeLists.txt b/examples/qml/tutorials/extending-qml/chapter1-basics/CMakeLists.txt index 7e1f1887c4..146ba6c887 100644 --- a/examples/qml/tutorials/extending-qml/chapter1-basics/CMakeLists.txt +++ b/examples/qml/tutorials/extending-qml/chapter1-basics/CMakeLists.txt @@ -1,6 +1,6 @@ # Generated from chapter1-basics.pro. -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(chapter1-basics LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) @@ -35,17 +35,12 @@ target_link_libraries(chapter1-basics PUBLIC Qt::Quick ) - -# Resources: -set(chapter1-basics_resource_files - "app.qml" -) - -qt6_add_resources(chapter1-basics "chapter1-basics" - PREFIX - "/" - FILES - ${chapter1-basics_resource_files} +qt_add_qml_module(chapter1-basics + URI Charts + VERSION 1.0 + QML_FILES app.qml + NO_RESOURCE_TARGET_PATH + DEPENDENCIES QtQuick ) install(TARGETS chapter1-basics @@ -53,10 +48,3 @@ install(TARGETS chapter1-basics BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) - -set_target_properties(chapter1-basics PROPERTIES - QT_QML_MODULE_VERSION 1.0 - QT_QML_MODULE_URI Charts -) - -qt6_qml_type_registration(chapter1-basics) diff --git a/examples/qml/tutorials/extending-qml/chapter1-basics/piechart.h b/examples/qml/tutorials/extending-qml/chapter1-basics/piechart.h index 687f8e2b4d..742f8ec0fd 100644 --- a/examples/qml/tutorials/extending-qml/chapter1-basics/piechart.h +++ b/examples/qml/tutorials/extending-qml/chapter1-basics/piechart.h @@ -57,8 +57,8 @@ class PieChart : public QQuickPaintedItem { Q_OBJECT - Q_PROPERTY(QString name READ name WRITE setName) - Q_PROPERTY(QColor color READ color WRITE setColor) + Q_PROPERTY(QString name READ name WRITE setName FINAL) + Q_PROPERTY(QColor color READ color WRITE setColor FINAL) QML_ELEMENT public: diff --git a/examples/qml/tutorials/extending-qml/chapter2-methods/CMakeLists.txt b/examples/qml/tutorials/extending-qml/chapter2-methods/CMakeLists.txt index 456c3965eb..c5e066cad0 100644 --- a/examples/qml/tutorials/extending-qml/chapter2-methods/CMakeLists.txt +++ b/examples/qml/tutorials/extending-qml/chapter2-methods/CMakeLists.txt @@ -1,6 +1,6 @@ # Generated from chapter2-methods.pro. -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(chapter2-methods LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) @@ -35,17 +35,12 @@ target_link_libraries(chapter2-methods PUBLIC Qt::Quick ) - -# Resources: -set(chapter2-methods_resource_files - "app.qml" -) - -qt6_add_resources(chapter2-methods "chapter2-methods" - PREFIX - "/" - FILES - ${chapter2-methods_resource_files} +qt_add_qml_module(chapter2-methods + URI Charts + VERSION 1.0 + QML_FILES app.qml + NO_RESOURCE_TARGET_PATH + DEPENDENCIES QtQuick ) install(TARGETS chapter2-methods @@ -53,10 +48,3 @@ install(TARGETS chapter2-methods BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) - -set_target_properties(chapter2-methods PROPERTIES - QT_QML_MODULE_VERSION 1.0 - QT_QML_MODULE_URI Charts -) - -qt6_qml_type_registration(chapter2-methods) diff --git a/examples/qml/tutorials/extending-qml/chapter2-methods/piechart.h b/examples/qml/tutorials/extending-qml/chapter2-methods/piechart.h index 271afbf653..6457a8561d 100644 --- a/examples/qml/tutorials/extending-qml/chapter2-methods/piechart.h +++ b/examples/qml/tutorials/extending-qml/chapter2-methods/piechart.h @@ -58,8 +58,8 @@ class PieChart : public QQuickPaintedItem { //![0] Q_OBJECT - Q_PROPERTY(QString name READ name WRITE setName) - Q_PROPERTY(QColor color READ color WRITE setColor) + Q_PROPERTY(QString name READ name WRITE setName FINAL) + Q_PROPERTY(QColor color READ color WRITE setColor FINAL) QML_ELEMENT //![1] public: diff --git a/examples/qml/tutorials/extending-qml/chapter3-bindings/CMakeLists.txt b/examples/qml/tutorials/extending-qml/chapter3-bindings/CMakeLists.txt index 6b81e93dff..184f440c1d 100644 --- a/examples/qml/tutorials/extending-qml/chapter3-bindings/CMakeLists.txt +++ b/examples/qml/tutorials/extending-qml/chapter3-bindings/CMakeLists.txt @@ -1,6 +1,6 @@ # Generated from chapter3-bindings.pro. -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(chapter3-bindings LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) @@ -35,17 +35,12 @@ target_link_libraries(chapter3-bindings PUBLIC Qt::Quick ) - -# Resources: -set(chapter3-bindings_resource_files - "app.qml" -) - -qt6_add_resources(chapter3-bindings "chapter3-bindings" - PREFIX - "/" - FILES - ${chapter3-bindings_resource_files} +qt_add_qml_module(chapter3-bindings + URI Charts + VERSION 1.0 + QML_FILES app.qml + NO_RESOURCE_TARGET_PATH + DEPENDENCIES QtQuick ) install(TARGETS chapter3-bindings @@ -53,10 +48,3 @@ install(TARGETS chapter3-bindings BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) - -set_target_properties(chapter3-bindings PROPERTIES - QT_QML_MODULE_VERSION 1.0 - QT_QML_MODULE_URI Charts -) - -qt6_qml_type_registration(chapter3-bindings) diff --git a/examples/qml/tutorials/extending-qml/chapter3-bindings/piechart.h b/examples/qml/tutorials/extending-qml/chapter3-bindings/piechart.h index 58b1339298..ef3f6a79dc 100644 --- a/examples/qml/tutorials/extending-qml/chapter3-bindings/piechart.h +++ b/examples/qml/tutorials/extending-qml/chapter3-bindings/piechart.h @@ -58,11 +58,11 @@ class PieChart : public QQuickPaintedItem { //![0] Q_OBJECT - Q_PROPERTY(QString name READ name WRITE setName) + Q_PROPERTY(QString name READ name WRITE setName FINAL) QML_ELEMENT //![1] - Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) + Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged FINAL) public: //![1] diff --git a/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/CMakeLists.txt b/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/CMakeLists.txt index 55fb20ea41..51855394e3 100644 --- a/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/CMakeLists.txt +++ b/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/CMakeLists.txt @@ -1,6 +1,6 @@ # Generated from chapter4-customPropertyTypes.pro. -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(chapter4-customPropertyTypes LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) @@ -36,17 +36,12 @@ target_link_libraries(chapter4-customPropertyTypes PUBLIC Qt::Quick ) - -# Resources: -set(chapter4-customPropertyTypes_resource_files - "app.qml" -) - -qt6_add_resources(chapter4-customPropertyTypes "chapter4-customPropertyTypes" - PREFIX - "/" - FILES - ${chapter4-customPropertyTypes_resource_files} +qt_add_qml_module(chapter4-customPropertyTypes + URI Charts + VERSION 1.0 + QML_FILES app.qml + NO_RESOURCE_TARGET_PATH + DEPENDENCIES QtQuick ) install(TARGETS chapter4-customPropertyTypes @@ -54,10 +49,3 @@ install(TARGETS chapter4-customPropertyTypes BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) - -set_target_properties(chapter4-customPropertyTypes PROPERTIES - QT_QML_MODULE_VERSION 1.0 - QT_QML_MODULE_URI Charts -) - -qt6_qml_type_registration(chapter4-customPropertyTypes) diff --git a/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/piechart.h b/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/piechart.h index 855ad7ae3a..57ef7d90e2 100644 --- a/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/piechart.h +++ b/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/piechart.h @@ -58,9 +58,9 @@ class PieSlice; class PieChart : public QQuickItem { Q_OBJECT - Q_PROPERTY(PieSlice* pieSlice READ pieSlice WRITE setPieSlice) + Q_PROPERTY(PieSlice* pieSlice READ pieSlice WRITE setPieSlice FINAL) //![0] - Q_PROPERTY(QString name READ name WRITE setName) + Q_PROPERTY(QString name READ name WRITE setName FINAL) Q_MOC_INCLUDE("pieslice.h") QML_ELEMENT //![1] diff --git a/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/pieslice.h b/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/pieslice.h index 6e64917851..84d1789e56 100644 --- a/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/pieslice.h +++ b/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/pieslice.h @@ -57,7 +57,7 @@ class PieSlice : public QQuickPaintedItem { Q_OBJECT - Q_PROPERTY(QColor color READ color WRITE setColor) + Q_PROPERTY(QColor color READ color WRITE setColor FINAL) QML_ELEMENT public: diff --git a/examples/qml/tutorials/extending-qml/chapter5-listproperties/CMakeLists.txt b/examples/qml/tutorials/extending-qml/chapter5-listproperties/CMakeLists.txt index f41a349eac..ac3f7839ab 100644 --- a/examples/qml/tutorials/extending-qml/chapter5-listproperties/CMakeLists.txt +++ b/examples/qml/tutorials/extending-qml/chapter5-listproperties/CMakeLists.txt @@ -1,6 +1,6 @@ # Generated from chapter5-listproperties.pro. -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(chapter5-listproperties LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) @@ -36,17 +36,12 @@ target_link_libraries(chapter5-listproperties PUBLIC Qt::Quick ) - -# Resources: -set(chapter5-listproperties_resource_files - "app.qml" -) - -qt6_add_resources(chapter5-listproperties "chapter5-listproperties" - PREFIX - "/" - FILES - ${chapter5-listproperties_resource_files} +qt_add_qml_module(chapter5-listproperties + URI Charts + VERSION 1.0 + QML_FILES app.qml + NO_RESOURCE_TARGET_PATH + DEPENDENCIES QtQuick ) install(TARGETS chapter5-listproperties @@ -54,10 +49,3 @@ install(TARGETS chapter5-listproperties BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) - -set_target_properties(chapter5-listproperties PROPERTIES - QT_QML_MODULE_VERSION 1.0 - QT_QML_MODULE_URI Charts -) - -qt6_qml_type_registration(chapter5-listproperties) diff --git a/examples/qml/tutorials/extending-qml/chapter5-listproperties/piechart.h b/examples/qml/tutorials/extending-qml/chapter5-listproperties/piechart.h index 236fa6796f..3caa80ed53 100644 --- a/examples/qml/tutorials/extending-qml/chapter5-listproperties/piechart.h +++ b/examples/qml/tutorials/extending-qml/chapter5-listproperties/piechart.h @@ -58,9 +58,9 @@ class PieSlice; class PieChart : public QQuickItem { Q_OBJECT - Q_PROPERTY(QQmlListProperty<PieSlice> slices READ slices) + Q_PROPERTY(QQmlListProperty<PieSlice> slices READ slices FINAL) //![0] - Q_PROPERTY(QString name READ name WRITE setName) + Q_PROPERTY(QString name READ name WRITE setName FINAL) QML_ELEMENT //![1] diff --git a/examples/qml/tutorials/extending-qml/chapter5-listproperties/pieslice.h b/examples/qml/tutorials/extending-qml/chapter5-listproperties/pieslice.h index 0b290851f0..50c573c7bc 100644 --- a/examples/qml/tutorials/extending-qml/chapter5-listproperties/pieslice.h +++ b/examples/qml/tutorials/extending-qml/chapter5-listproperties/pieslice.h @@ -57,9 +57,9 @@ class PieSlice : public QQuickPaintedItem { Q_OBJECT - Q_PROPERTY(QColor color READ color WRITE setColor) - Q_PROPERTY(int fromAngle READ fromAngle WRITE setFromAngle) - Q_PROPERTY(int angleSpan READ angleSpan WRITE setAngleSpan) + Q_PROPERTY(QColor color READ color WRITE setColor FINAL) + Q_PROPERTY(int fromAngle READ fromAngle WRITE setFromAngle FINAL) + Q_PROPERTY(int angleSpan READ angleSpan WRITE setAngleSpan FINAL) QML_ELEMENT //![0] diff --git a/examples/qml/tutorials/extending-qml/chapter6-plugins/.prev_CMakeLists.txt b/examples/qml/tutorials/extending-qml/chapter6-plugins/.prev_CMakeLists.txt deleted file mode 100644 index 0d68df497a..0000000000 --- a/examples/qml/tutorials/extending-qml/chapter6-plugins/.prev_CMakeLists.txt +++ /dev/null @@ -1,51 +0,0 @@ -# Generated from chapter6-plugins.pro. - -cmake_minimum_required(VERSION 3.14) -project(chapter6-plugins LANGUAGES CXX) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(CMAKE_AUTOMOC ON) -set(CMAKE_AUTORCC ON) -set(CMAKE_AUTOUIC 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 COMPONENTS Qml) -find_package(Qt6 COMPONENTS Quick) - -qt_add_executable(chapter6-plugins - main.cpp -) -set_target_properties(chapter6-plugins PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) -target_link_libraries(chapter6-plugins PUBLIC - Qt::Qml - Qt::Quick -) - - -# Resources: -set(app_resource_files - "app.qml" -) - -qt6_add_resources(chapter6-plugins "app" - PREFIX - "/" - FILES - ${app_resource_files} -) - -install(TARGETS chapter6-plugins - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) -add_subdirectory(import) diff --git a/examples/qml/tutorials/extending-qml/chapter6-plugins/CMakeLists.txt b/examples/qml/tutorials/extending-qml/chapter6-plugins/CMakeLists.txt index 59ecdeae6b..dc0b20dc21 100644 --- a/examples/qml/tutorials/extending-qml/chapter6-plugins/CMakeLists.txt +++ b/examples/qml/tutorials/extending-qml/chapter6-plugins/CMakeLists.txt @@ -1,6 +1,6 @@ # Generated from chapter6-plugins.pro. -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(chapter6-plugins LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) @@ -14,7 +14,6 @@ if(NOT DEFINED INSTALL_EXAMPLESDIR) endif() set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/qml/tutorials/extending-qml/chapter6-plugins") -set(QT_QML_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) find_package(Qt6 COMPONENTS Qml) find_package(Qt6 COMPONENTS Quick) @@ -26,22 +25,16 @@ set_target_properties(chapter6-plugins PROPERTIES WIN32_EXECUTABLE TRUE MACOSX_BUNDLE TRUE ) -target_link_libraries(chapter6-plugins PUBLIC +target_link_libraries(chapter6-plugins PRIVATE Qt::Qml Qt::Quick ) - -# Resources: -set(app_resource_files - "app.qml" -) - -qt6_add_resources(chapter6-plugins "app" - PREFIX - "/" - FILES - ${app_resource_files} +qt_add_qml_module(chapter6-plugins + URI ChartsApp + VERSION 1.0 + QML_FILES app.qml + NO_RESOURCE_TARGET_PATH ) install(TARGETS chapter6-plugins @@ -50,4 +43,4 @@ install(TARGETS chapter6-plugins LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) -add_subdirectory(import) +add_subdirectory(Charts) diff --git a/examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/CMakeLists.txt b/examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/CMakeLists.txt new file mode 100644 index 0000000000..62d4c71fc4 --- /dev/null +++ b/examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/CMakeLists.txt @@ -0,0 +1,49 @@ +qt6_add_qml_module(chartsplugin + VERSION 1.0 + URI "Charts" + PLUGIN_TARGET chartsplugin + DEPENDENCIES QtQuick +) + +target_sources(chartsplugin PRIVATE + piechart.cpp piechart.h + pieslice.cpp pieslice.h +) + +target_link_libraries(chartsplugin PRIVATE + Qt::Core + Qt::Gui + Qt::Qml + Qt::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} + ) + endif() +endif() + +set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLEDIR}/Charts") +install(TARGETS chartsplugin + RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" + BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" + LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" +) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/qmldir + DESTINATION "${INSTALL_EXAMPLEDIR}") diff --git a/examples/qml/tutorials/extending-qml/chapter6-plugins/import/import.pro b/examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/Charts.pro index c37cd1fdee..e3763b6f5e 100644 --- a/examples/qml/tutorials/extending-qml/chapter6-plugins/import/import.pro +++ b/examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/Charts.pro @@ -5,7 +5,6 @@ QT += qml quick QML_IMPORT_NAME = Charts QML_IMPORT_MAJOR_VERSION = 1 -DESTDIR = ../$$QML_IMPORT_NAME TARGET = $$qtLibraryTarget(chartsplugin) HEADERS += piechart.h \ @@ -17,10 +16,6 @@ SOURCES += piechart.cpp \ DESTPATH=$$[QT_INSTALL_EXAMPLES]/qml/tutorials/extending-qml/chapter6-plugins/$$QML_IMPORT_NAME -copy_qmltypes.files = $$OUT_PWD/plugins.qmltypes -copy_qmltypes.path = $$DESTDIR -COPIES += copy_qmltypes - target.path=$$DESTPATH qmldir.files=$$PWD/qmldir qmldir.path=$$DESTPATH @@ -32,5 +27,5 @@ OTHER_FILES += qmldir # Copy the qmldir file to the same folder as the plugin binary cpqmldir.files = qmldir -cpqmldir.path = $$DESTDIR +cpqmldir.path = . COPIES += cpqmldir diff --git a/examples/qml/tutorials/extending-qml/chapter6-plugins/import/chartsplugin.h b/examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/chartsplugin.h index 780bb3a8f3..780bb3a8f3 100644 --- a/examples/qml/tutorials/extending-qml/chapter6-plugins/import/chartsplugin.h +++ b/examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/chartsplugin.h diff --git a/examples/qml/tutorials/extending-qml/chapter6-plugins/import/piechart.cpp b/examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/piechart.cpp index 536c0e16ae..536c0e16ae 100644 --- a/examples/qml/tutorials/extending-qml/chapter6-plugins/import/piechart.cpp +++ b/examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/piechart.cpp diff --git a/examples/qml/tutorials/extending-qml/chapter6-plugins/import/piechart.h b/examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/piechart.h index e6b768b274..d48f217ea4 100644 --- a/examples/qml/tutorials/extending-qml/chapter6-plugins/import/piechart.h +++ b/examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/piechart.h @@ -57,8 +57,8 @@ class PieSlice; class PieChart : public QQuickItem { Q_OBJECT - Q_PROPERTY(QQmlListProperty<PieSlice> slices READ slices) - Q_PROPERTY(QString name READ name WRITE setName) + Q_PROPERTY(QQmlListProperty<PieSlice> slices READ slices FINAL) + Q_PROPERTY(QString name READ name WRITE setName FINAL) QML_ELEMENT public: diff --git a/examples/qml/tutorials/extending-qml/chapter6-plugins/import/pieslice.cpp b/examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/pieslice.cpp index 1d30036929..1d30036929 100644 --- a/examples/qml/tutorials/extending-qml/chapter6-plugins/import/pieslice.cpp +++ b/examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/pieslice.cpp diff --git a/examples/qml/tutorials/extending-qml/chapter6-plugins/import/pieslice.h b/examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/pieslice.h index 091870bd51..965b50f058 100644 --- a/examples/qml/tutorials/extending-qml/chapter6-plugins/import/pieslice.h +++ b/examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/pieslice.h @@ -56,9 +56,9 @@ class PieSlice : public QQuickPaintedItem { Q_OBJECT - Q_PROPERTY(QColor color READ color WRITE setColor) - Q_PROPERTY(int fromAngle READ fromAngle WRITE setFromAngle) - Q_PROPERTY(int angleSpan READ angleSpan WRITE setAngleSpan) + Q_PROPERTY(QColor color READ color WRITE setColor FINAL) + Q_PROPERTY(int fromAngle READ fromAngle WRITE setFromAngle FINAL) + Q_PROPERTY(int angleSpan READ angleSpan WRITE setAngleSpan FINAL) QML_ELEMENT public: diff --git a/examples/qml/tutorials/extending-qml/chapter6-plugins/import/qmldir b/examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/qmldir index d9e8471b3c..d9e8471b3c 100644 --- a/examples/qml/tutorials/extending-qml/chapter6-plugins/import/qmldir +++ b/examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/qmldir diff --git a/examples/qml/tutorials/extending-qml/chapter6-plugins/app.pro b/examples/qml/tutorials/extending-qml/chapter6-plugins/app.pro index b340981e42..8f53075a7d 100644 --- a/examples/qml/tutorials/extending-qml/chapter6-plugins/app.pro +++ b/examples/qml/tutorials/extending-qml/chapter6-plugins/app.pro @@ -3,9 +3,9 @@ QT += qml quick # Ensure that the application will see the import path for the Charts module: # * On Windows, do not build into a debug/release subdirectory. -# * On OS X, add the plugin files into the bundle. +# * On macOS, add the plugin files into the bundle, only in a shared build though win32: DESTDIR = ./ -osx { +macos:!qtConfig(static) { charts.files = $$OUT_PWD/Charts charts.path = Contents/PlugIns QMAKE_BUNDLE_DATA += charts diff --git a/examples/qml/tutorials/extending-qml/chapter6-plugins/chapter6-plugins.pro b/examples/qml/tutorials/extending-qml/chapter6-plugins/chapter6-plugins.pro index f858c80876..2d78235454 100644 --- a/examples/qml/tutorials/extending-qml/chapter6-plugins/chapter6-plugins.pro +++ b/examples/qml/tutorials/extending-qml/chapter6-plugins/chapter6-plugins.pro @@ -1,5 +1,5 @@ TEMPLATE = subdirs CONFIG += ordered SUBDIRS = \ - import \ + Charts \ app.pro diff --git a/examples/qml/tutorials/extending-qml/chapter6-plugins/import/CMakeLists.txt b/examples/qml/tutorials/extending-qml/chapter6-plugins/import/CMakeLists.txt deleted file mode 100644 index 93ec5c5169..0000000000 --- a/examples/qml/tutorials/extending-qml/chapter6-plugins/import/CMakeLists.txt +++ /dev/null @@ -1,48 +0,0 @@ -# Generated from import.pro. - -cmake_minimum_required(VERSION 3.14) -project(chartsplugin LANGUAGES CXX) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(CMAKE_AUTOMOC ON) -set(CMAKE_AUTORCC ON) -set(CMAKE_AUTOUIC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/qml/tutorials/extending-qml/chapter6-plugins/Charts") - -find_package(Qt6 COMPONENTS Core) -find_package(Qt6 COMPONENTS Gui) -find_package(Qt6 COMPONENTS Qml) -find_package(Qt6 COMPONENTS Quick) - -qt6_add_qml_module(chartsplugin - VERSION 1.0 - URI "Charts" - PLUGIN_TARGET chartsplugin -) - -target_sources(chartsplugin PRIVATE - piechart.cpp piechart.h - pieslice.cpp pieslice.h -) -set_target_properties(chartsplugin PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) -target_link_libraries(chartsplugin PUBLIC - Qt::Core - Qt::Gui - Qt::Qml - Qt::Quick -) - -install(TARGETS chartsplugin - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/qml/xmlhttprequest/CMakeLists.txt b/examples/qml/xmlhttprequest/CMakeLists.txt index ebb0d0c011..a3fe890634 100644 --- a/examples/qml/xmlhttprequest/CMakeLists.txt +++ b/examples/qml/xmlhttprequest/CMakeLists.txt @@ -1,13 +1,12 @@ # Generated from xmlhttprequest.pro. -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(xmlhttprequest LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) -set(CMAKE_AUTOUIC ON) if(NOT DEFINED INSTALL_EXAMPLESDIR) set(INSTALL_EXAMPLESDIR "examples") @@ -15,65 +14,32 @@ endif() set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/qml/xmlhttprequest") -find_package(Qt6 COMPONENTS Core) -find_package(Qt6 COMPONENTS Gui) -find_package(Qt6 COMPONENTS Quick) -find_package(Qt6 COMPONENTS Qml) +find_package(Qt6 COMPONENTS Core Gui Quick Qml) -qt_add_executable(xmlhttprequest +qt_add_executable(xmlhttprequestexample + WIN32 + MACOSX_BUNDLE main.cpp ) -set_target_properties(xmlhttprequest PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE + +qt_add_qml_module(xmlhttprequestexample + URI xmlhttprequest + VERSION 1.0 + QML_FILES + "methods.js" + "xmlhttprequest.qml" + RESOURCES + data.xml ) -target_link_libraries(xmlhttprequest PUBLIC + +target_link_libraries(xmlhttprequestexample PUBLIC Qt::Core Qt::Gui Qt::Qml Qt::Quick ) - -# Resources: -set(xmlhttprequest_resource_files - "Get.qml" - "GetForm.ui.qml" - "data.xml" - "methods.js" - "xmlhttprequest.qml" -) - -qt6_add_resources(xmlhttprequest "xmlhttprequest" - PREFIX - "/qml/xmlhttprequest" - FILES - ${xmlhttprequest_resource_files} -) -set(quick_shared_resource_files - "../../quick/shared/Button.qml" - "../../quick/shared/CheckBox.qml" - "../../quick/shared/Label.qml" - "../../quick/shared/LauncherList.qml" - "../../quick/shared/SimpleLauncherDelegate.qml" - "../../quick/shared/Slider.qml" - "../../quick/shared/TextField.qml" - "../../quick/shared/images/back.png" - "../../quick/shared/images/checkmark.png" - "../../quick/shared/images/next.png" - "../../quick/shared/images/slider_handle.png" -) - -qt6_add_resources(xmlhttprequest "quick_shared" - PREFIX - "/quick/shared" - BASE - "../../quick/shared" - FILES - ${quick_shared_resource_files} -) - -install(TARGETS xmlhttprequest +install(TARGETS xmlhttprequestexample RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" diff --git a/examples/qml/xmlhttprequest/Get.qml b/examples/qml/xmlhttprequest/Get.qml deleted file mode 100644 index 96cec2a99d..0000000000 --- a/examples/qml/xmlhttprequest/Get.qml +++ /dev/null @@ -1,64 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, you may use this file under the terms of the BSD license -** as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of The Qt Company Ltd nor the names of its -** contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.0 - -import "methods.js" as Utils - -GetForm -{ - anchors.fill: parent - - mouseArea.onClicked: Utils.makeRequest() - - button.border.width: mouseArea.pressed ? 2 : 1 - text.text: "Request data.xml" - -} diff --git a/examples/qml/xmlhttprequest/GetForm.ui.qml b/examples/qml/xmlhttprequest/GetForm.ui.qml deleted file mode 100644 index 284299ef35..0000000000 --- a/examples/qml/xmlhttprequest/GetForm.ui.qml +++ /dev/null @@ -1,83 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, you may use this file under the terms of the BSD license -** as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of The Qt Company Ltd nor the names of its -** contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.0 - - -Rectangle { - id:rect - width: 350 - height: 400 - - property alias button: button - property alias text: buttonText - property alias mouseArea: mouseArea - property alias msg: ttext - - Text { id: ttext; anchors.fill: parent; anchors.margins: 10 } - - Rectangle { - id: button - anchors.horizontalCenter: parent.horizontalCenter; - anchors.bottom: parent.bottom - anchors.margins: 10 - width: buttonText.width + 10 - height: buttonText.height + 10 - radius : 5; antialiasing: true - - Text { id: buttonText; anchors.centerIn: parent } - - MouseArea { - id: mouseArea - anchors.fill: parent - } - } -} - diff --git a/examples/qml/xmlhttprequest/main.cpp b/examples/qml/xmlhttprequest/main.cpp index 02be6d2196..cef60a5e6f 100644 --- a/examples/qml/xmlhttprequest/main.cpp +++ b/examples/qml/xmlhttprequest/main.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. @@ -47,5 +47,27 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ -#include "../../quick/shared/shared.h" -DECLARATIVE_EXAMPLE_MAIN(qml/xmlhttprequest/xmlhttprequest) + +#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:///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/xmlhttprequest.pro b/examples/qml/xmlhttprequest/xmlhttprequest.pro index 3b78db0252..6d572fff59 100644 --- a/examples/qml/xmlhttprequest/xmlhttprequest.pro +++ b/examples/qml/xmlhttprequest/xmlhttprequest.pro @@ -3,8 +3,7 @@ TEMPLATE = app QT += quick qml SOURCES += main.cpp RESOURCES += \ - xmlhttprequest.qrc \ - ../../quick/shared/quick_shared.qrc + xmlhttprequest.qrc EXAMPLE_FILES = \ data.xml @@ -13,6 +12,4 @@ target.path = $$[QT_INSTALL_EXAMPLES]/qml/xmlhttprequest INSTALLS += target DISTFILES += \ - Get.qml \ - GetForm.ui.qml \ methods.js diff --git a/examples/qml/xmlhttprequest/xmlhttprequest.qml b/examples/qml/xmlhttprequest/xmlhttprequest.qml index e6c7b10e16..31aa1824e9 100644 --- a/examples/qml/xmlhttprequest/xmlhttprequest.qml +++ b/examples/qml/xmlhttprequest/xmlhttprequest.qml @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. @@ -48,17 +48,28 @@ ** ****************************************************************************/ -import QtQuick 2.0 -import "../../quick/shared" as Examples +import QtQuick +import QtQuick.Controls +import "methods.js" as Utils + Item { height: 480 width: 320 - Examples.LauncherList { - id: ll - anchors.fill: parent - Component.onCompleted: { - addExample("Get data", "Send get request and show received header and body", Qt.resolvedUrl("Get.qml")); - } + + 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.qrc b/examples/qml/xmlhttprequest/xmlhttprequest.qrc index 2e5dae4bb8..75c0edca8a 100644 --- a/examples/qml/xmlhttprequest/xmlhttprequest.qrc +++ b/examples/qml/xmlhttprequest/xmlhttprequest.qrc @@ -1,9 +1,7 @@ <RCC> - <qresource prefix="/qml/xmlhttprequest"> + <qresource prefix="/xmlhttprequest"> <file>xmlhttprequest.qml</file> - <file>data.xml</file> <file>methods.js</file> - <file>Get.qml</file> - <file>GetForm.ui.qml</file> + <file>data.xml</file> </qresource> </RCC> |