diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2021-08-27 16:19:54 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-08-30 20:56:36 +0000 |
commit | a54c50ac9cdb6461b8a73acec154ef11aa571c57 (patch) | |
tree | 8c64e5006c0d41720d478befa70d4c0889368b7b /examples | |
parent | 1b359cf597f51aaea7f751f6286e49359d826ac3 (diff) |
Fix the qtquick/window example to use QML modules
The shared code becomes its own module. Due to the ${PROJECT_NAME} trick
it should be possible to include it multiple times, in different
examples.
Change-Id: I78cc3211f67fae9a713320fae4041898e6a397ed
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Oliver Eftevaag <oliver.eftevaag@qt.io>
(cherry picked from commit 7b6eea37aeea55cdf1bcb1fd9c3091d6753f95e8)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'examples')
-rw-r--r-- | examples/quick/shared/CMakeLists.txt | 47 | ||||
-rw-r--r-- | examples/quick/shared/Images.qml | 61 | ||||
-rw-r--r-- | examples/quick/shared/qmldir | 4 | ||||
-rw-r--r-- | examples/quick/shared/shared.qrc | 12 | ||||
-rw-r--r-- | examples/quick/window/CMakeLists.txt | 64 | ||||
-rw-r--r-- | examples/quick/window/Splash.qml | 3 | ||||
-rw-r--r-- | examples/quick/window/main.cpp | 4 |
7 files changed, 143 insertions, 52 deletions
diff --git a/examples/quick/shared/CMakeLists.txt b/examples/quick/shared/CMakeLists.txt new file mode 100644 index 0000000000..9c24562eb3 --- /dev/null +++ b/examples/quick/shared/CMakeLists.txt @@ -0,0 +1,47 @@ +qt_add_library(${PROJECT_NAME}_shared) + +set_source_files_properties(CheckBox.qml TabSet.qml TextField.qml + PROPERTIES + QT_QML_SOURCE_VERSIONS 2.1 +) + +set_source_files_properties(Images.qml + PROPERTIES + QT_QML_SINGLETON_TYPE true + QT_QML_SOURCE_VERSIONS 2.2 +) + +qt_add_qml_module(${PROJECT_NAME}_shared + URI shared + VERSION 2.2 + PLUGIN_TARGET ${PROJECT_NAME}_shared + SOURCES + "shared.h" + QML_FILES + "Button.qml" + "CheckBox.qml" + "FlickrRssModel.qml" + "Label.qml" + "LauncherList.qml" + "SimpleLauncherDelegate.qml" + "Slider.qml" + "TabSet.qml" + "TextField.qml" + "Images.qml" + RESOURCES + "images/back.png" + "images/checkmark.png" + "images/next.png" + "images/qt-logo.png" + "images/slider_handle.png" + "images/tab.png" +) + +set(INSTALL_SHAREDDIR "${INSTALL_EXAMPLESDIR}/quick/${PROJECT_NAME}/shared") +install(TARGETS ${PROJECT_NAME}_shared + RUNTIME DESTINATION "${INSTALL_SHAREDDIR}" + LIBRARY DESTINATION "${INSTALL_SHAREDDIR}" +) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/qmldir + DESTINATION "${INSTALL_SHAREDDIR}" +) diff --git a/examples/quick/shared/Images.qml b/examples/quick/shared/Images.qml new file mode 100644 index 0000000000..f3093cc841 --- /dev/null +++ b/examples/quick/shared/Images.qml @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2021 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$ +** +****************************************************************************/ + +pragma Singleton +import QtQml + +QtObject { + readonly property url back: Qt.resolvedUrl("images/back.png") + readonly property url checkmark: Qt.resolvedUrl("images/checkmark.png") + readonly property url next: Qt.resolvedUrl("images/next.png") + readonly property url qtLogo: Qt.resolvedUrl("images/qt-logo.png") + readonly property url sliderHandle: Qt.resolvedUrl("images/slider_handle.png") + readonly property url tab: Qt.resolvedUrl("images/tab.png") +} diff --git a/examples/quick/shared/qmldir b/examples/quick/shared/qmldir index b539191fec..5ccdf60219 100644 --- a/examples/quick/shared/qmldir +++ b/examples/quick/shared/qmldir @@ -1,7 +1,11 @@ +module shared Button 2.0 Button.qml CheckBox 2.1 CheckBox.qml +FlickrRssModel 2.0 FlickrRssModel.qml +Label 2.0 Label.qml LauncherList 2.0 LauncherList.qml SimpleLauncherDelegate 2.0 SimpleLauncherDelegate.qml Slider 2.0 Slider.qml TabSet 2.1 TabSet.qml TextField 2.1 TextField.qml +singleton Images 2.2 Images.qml diff --git a/examples/quick/shared/shared.qrc b/examples/quick/shared/shared.qrc index cce683f8a3..c19063a585 100644 --- a/examples/quick/shared/shared.qrc +++ b/examples/quick/shared/shared.qrc @@ -1,19 +1,21 @@ <RCC> <qresource prefix="/shared"> + <file>Button.qml</file> + <file>CheckBox.qml</file> <file>FlickrRssModel.qml</file> + <file>Images.qml</file> + <file>Label.qml</file> <file>LauncherList.qml</file> <file>SimpleLauncherDelegate.qml</file> - <file>Button.qml</file> <file>Slider.qml</file> - <file>images/slider_handle.png</file> - <file>CheckBox.qml</file> - <file>Label.qml</file> <file>TabSet.qml</file> <file>TextField.qml</file> <file>images/back.png</file> + <file>images/checkmark.png</file> <file>images/next.png</file> <file>images/qt-logo.png</file> - <file>images/checkmark.png</file> + <file>images/slider_handle.png</file> <file>images/tab.png</file> + <file>qmldir</file> </qresource> </RCC> diff --git a/examples/quick/window/CMakeLists.txt b/examples/quick/window/CMakeLists.txt index 1a46346a19..a2340f700f 100644 --- a/examples/quick/window/CMakeLists.txt +++ b/examples/quick/window/CMakeLists.txt @@ -20,63 +20,35 @@ find_package(Qt6 COMPONENTS Gui) find_package(Qt6 COMPONENTS Quick) find_package(Qt6 COMPONENTS Qml) -qt_add_executable(window +add_subdirectory("../shared" "shared") + +qt_add_executable(windowexample main.cpp ) -set_target_properties(window PROPERTIES +set_target_properties(windowexample PROPERTIES WIN32_EXECUTABLE TRUE MACOSX_BUNDLE TRUE ) -target_link_libraries(window PUBLIC + +qt_add_qml_module(windowexample + URI window + VERSION 1.0 + QML_FILES + "AllScreens.qml" + "CurrentScreen.qml" + "Splash.qml" + "window.qml" +) + +target_link_libraries(windowexample PRIVATE Qt::Core Qt::Gui Qt::Qml Qt::Quick + window_shared ) - -# Resources: -set(window_resource_files - "AllScreens.qml" - "CurrentScreen.qml" - "Splash.qml" - "window.qml" -) - -qt6_add_resources(window "window" - PREFIX - "/window" - FILES - ${window_resource_files} -) -set(shared_resource_files - "../shared/Button.qml" - "../shared/CheckBox.qml" - "../shared/FlickrRssModel.qml" - "../shared/Label.qml" - "../shared/LauncherList.qml" - "../shared/SimpleLauncherDelegate.qml" - "../shared/Slider.qml" - "../shared/TabSet.qml" - "../shared/TextField.qml" - "../shared/images/back.png" - "../shared/images/checkmark.png" - "../shared/images/next.png" - "../shared/images/qt-logo.png" - "../shared/images/slider_handle.png" - "../shared/images/tab.png" -) - -qt6_add_resources(window "shared" - PREFIX - "/shared" - BASE - "../shared" - FILES - ${shared_resource_files} -) - -install(TARGETS window +install(TARGETS windowexample RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" diff --git a/examples/quick/window/Splash.qml b/examples/quick/window/Splash.qml index cc520bd5a4..b19e6f81e3 100644 --- a/examples/quick/window/Splash.qml +++ b/examples/quick/window/Splash.qml @@ -49,6 +49,7 @@ ****************************************************************************/ import QtQuick +import shared //! [splash-properties] Window { @@ -69,7 +70,7 @@ Window { Image { id: splashImage - source: "../shared/images/qt-logo.png" + source: Images.qtLogo MouseArea { anchors.fill: parent onClicked: Qt.quit() diff --git a/examples/quick/window/main.cpp b/examples/quick/window/main.cpp index 25eb3663ab..baf31bc846 100644 --- a/examples/quick/window/main.cpp +++ b/examples/quick/window/main.cpp @@ -60,6 +60,10 @@ int main(int argc, char* argv[]) { QGuiApplication app(argc, argv); QQmlEngine engine; + + // Add the qrc root as QML import path so that the "shared" module can be found. + engine.addImportPath(QStringLiteral(":/")); + QQmlComponent component(&engine); QQuickWindow::setDefaultAlphaBuffer(true); component.loadUrl(QUrl("qrc:///window/window.qml")); |