Update qml examples for improved target path handling

Some examples were still using the old "add as ordinary resources"
approach for QML modules, others needed adjustment to the subdirectory
structure to better reflect the URI structure of the QML modules
involved.

Task-number: QTBUG-95144
Pick-to: 6.2
Change-Id: Ie3399410cf6df491eb1e7b4a589ca26c577d82a0
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
Craig Scott 2021-08-23 16:29:18 +10:00
parent 05bee5bb50
commit 9e1d2a0eb1
32 changed files with 121 additions and 416 deletions

View File

@ -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()

View File

@ -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

View File

@ -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}"

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -35,17 +35,11 @@ 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
)
install(TARGETS chapter1-basics
@ -53,10 +47,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)

View File

@ -35,17 +35,11 @@ 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
)
install(TARGETS chapter2-methods
@ -53,10 +47,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)

View File

@ -35,17 +35,11 @@ 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
)
install(TARGETS chapter3-bindings
@ -53,10 +47,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)

View File

@ -36,17 +36,11 @@ 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
)
install(TARGETS chapter4-customPropertyTypes
@ -54,10 +48,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)

View File

@ -36,17 +36,11 @@ 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
)
install(TARGETS chapter5-listproperties
@ -54,10 +48,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)

View File

@ -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)

View File

@ -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)
@ -31,17 +30,11 @@ target_link_libraries(chapter6-plugins PUBLIC
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)

View File

@ -17,10 +17,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

View File

@ -1,5 +1,5 @@
TEMPLATE = subdirs
CONFIG += ordered
SUBDIRS = \
import \
Charts \
app.pro

View File

@ -34,22 +34,21 @@ target_link_libraries(xmlhttprequest PUBLIC
Qt::Quick
)
# Resources:
set(xmlhttprequest_resource_files
"Get.qml"
"GetForm.ui.qml"
"data.xml"
"methods.js"
"xmlhttprequest.qml"
set(QT_QML_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/qml)
qt_add_qml_module(xmlhttprequest
URI xmlhttprequest
VERSION 1.0
QML_FILES
Get.qml
GetForm.ui.qml
methods.js
xmlhttprequest.qml
RESOURCES
data.xml
RESOURCE_PREFIX /qml
)
qt6_add_resources(xmlhttprequest "xmlhttprequest"
PREFIX
"/qml/xmlhttprequest"
FILES
${xmlhttprequest_resource_files}
)
# These files live outside of the QML module, so add them separately
set(quick_shared_resource_files
"../../quick/shared/Button.qml"
"../../quick/shared/CheckBox.qml"