From 643b58a4298f5a901674658f5937f55ca4a83205 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kai=20K=C3=B6hne?= Date: Tue, 17 Aug 2021 13:14:18 +0200 Subject: Rewrite Qt Resource System overview Restructure the Qt Resource System page to make the content more accessible, and coherent: - Focus less on the .qrc file format, but the overall use cases - Treat CMake as first-class citizen - Make it more obvious when to use :/, and when qrc:/ Some details that were deemed unnecessary were removed: - details about the internal naming of the .cpp file when qmake is used. - References to QDir::addSearchPath() and the search path list were removed. They relate IMO only indirectly to the Qt resource system. - A lot of the explanation around Q_INIT_RESOURCE/Q_CLEANUP_RESOURCE were dubious at best. Pick-to: 6.2 6.2.0 Fixes: QTBUG-95126 Fixes: QTBUG-94977 Fixes: QTBUG-59394 Task-number: QTBUG-88044 Change-Id: I04b64f2366631b2106f047de121daf5fdb01073d Reviewed-by: Alexey Edelev --- .../doc/snippets/resource-system/CMakeLists.txt | 31 ++++++--- .../doc/snippets/resource-system/application.pro | 25 ++++++- .../doc/snippets/resource-system/application.qrc | 18 ++--- .../doc/snippets/resource-system/images/copy.png | Bin 0 -> 67 bytes .../doc/snippets/resource-system/images/cut.png | Bin 0 -> 67 bytes .../doc/snippets/resource-system/images/new.png | Bin 0 -> 67 bytes .../doc/snippets/resource-system/images/open.png | Bin 0 -> 67 bytes .../doc/snippets/resource-system/images/paste.png | Bin 0 -> 67 bytes .../doc/snippets/resource-system/images/save.png | Bin 0 -> 67 bytes src/corelib/doc/snippets/resource-system/main.cpp | 75 +++++++++++++++++++++ 10 files changed, 131 insertions(+), 18 deletions(-) create mode 100644 src/corelib/doc/snippets/resource-system/images/copy.png create mode 100644 src/corelib/doc/snippets/resource-system/images/cut.png create mode 100644 src/corelib/doc/snippets/resource-system/images/new.png create mode 100644 src/corelib/doc/snippets/resource-system/images/open.png create mode 100644 src/corelib/doc/snippets/resource-system/images/paste.png create mode 100644 src/corelib/doc/snippets/resource-system/images/save.png create mode 100644 src/corelib/doc/snippets/resource-system/main.cpp (limited to 'src/corelib/doc/snippets') diff --git a/src/corelib/doc/snippets/resource-system/CMakeLists.txt b/src/corelib/doc/snippets/resource-system/CMakeLists.txt index 29727bd958..a488d869e6 100644 --- a/src/corelib/doc/snippets/resource-system/CMakeLists.txt +++ b/src/corelib/doc/snippets/resource-system/CMakeLists.txt @@ -1,23 +1,38 @@ project(my_app) cmake_minimum_required(VERSION 3.16) -find_package(Qt6 REQUIRED COMPONENTS Widgets) +find_package(Qt6 COMPONENTS Widgets Qml REQUIRED) #! [AUTORCC] set(CMAKE_AUTORCC ON) qt_add_executable(my_app application.qrc - mainwindow.cpp) + main.cpp +) #! [AUTORCC] #! [qt_add_resources] qt_add_resources(my_app "app_images" PREFIX "/" FILES - "images/copy.png" - "images/cut.png" - "images/new.png" - "images/open.png" - "images/paste.png" - "images/save.png") + images/copy.png + images/cut.png + images/new.png + images/open.png + images/paste.png + images/save.png +) #! [qt_add_resources] + +#! [qt_add_big_resources] +qt_add_big_resources(SOURCES application.qrc) +target_sources(my_app PRIVATE ${SOURCES}) +#! [qt_add_big_resources] + +#! [qt_add_binary_resources] +qt_add_binary_resources(resources application.qrc DESTINATION application.rcc) +add_dependencies(my_app resources) +#! [qt_add_binary_resources] + +target_link_libraries(my_app + PRIVATE Qt6::Qml Qt6::Widgets) diff --git a/src/corelib/doc/snippets/resource-system/application.pro b/src/corelib/doc/snippets/resource-system/application.pro index ecf4ce1093..4b1f1d7635 100644 --- a/src/corelib/doc/snippets/resource-system/application.pro +++ b/src/corelib/doc/snippets/resource-system/application.pro @@ -1,3 +1,26 @@ +TEMPLATE = app + +QT += qml widgets + #! [0] -RESOURCES = application.qrc +RESOURCES = application.qrc #! [0] + +#! [1] +resources.files = \ + images/copy.png \ + images/cut.png \ + images/new.png \ + images/open.png \ + images/paste.png \ + images/save.png +resources.prefix = / + +RESOURCES = resources +#! [1] + +#! [2] +CONFIG += resources_big +#! [2] + +SOURCES += main.cpp diff --git a/src/corelib/doc/snippets/resource-system/application.qrc b/src/corelib/doc/snippets/resource-system/application.qrc index 0a776fab4d..3eef379234 100644 --- a/src/corelib/doc/snippets/resource-system/application.qrc +++ b/src/corelib/doc/snippets/resource-system/application.qrc @@ -1,10 +1,10 @@ - - - images/copy.png - images/cut.png - images/new.png - images/open.png - images/paste.png - images/save.png - + + + images/copy.png + images/cut.png + images/new.png + images/open.png + images/paste.png + images/save.png + diff --git a/src/corelib/doc/snippets/resource-system/images/copy.png b/src/corelib/doc/snippets/resource-system/images/copy.png new file mode 100644 index 0000000000..91a99b94e2 Binary files /dev/null and b/src/corelib/doc/snippets/resource-system/images/copy.png differ diff --git a/src/corelib/doc/snippets/resource-system/images/cut.png b/src/corelib/doc/snippets/resource-system/images/cut.png new file mode 100644 index 0000000000..91a99b94e2 Binary files /dev/null and b/src/corelib/doc/snippets/resource-system/images/cut.png differ diff --git a/src/corelib/doc/snippets/resource-system/images/new.png b/src/corelib/doc/snippets/resource-system/images/new.png new file mode 100644 index 0000000000..91a99b94e2 Binary files /dev/null and b/src/corelib/doc/snippets/resource-system/images/new.png differ diff --git a/src/corelib/doc/snippets/resource-system/images/open.png b/src/corelib/doc/snippets/resource-system/images/open.png new file mode 100644 index 0000000000..91a99b94e2 Binary files /dev/null and b/src/corelib/doc/snippets/resource-system/images/open.png differ diff --git a/src/corelib/doc/snippets/resource-system/images/paste.png b/src/corelib/doc/snippets/resource-system/images/paste.png new file mode 100644 index 0000000000..91a99b94e2 Binary files /dev/null and b/src/corelib/doc/snippets/resource-system/images/paste.png differ diff --git a/src/corelib/doc/snippets/resource-system/images/save.png b/src/corelib/doc/snippets/resource-system/images/save.png new file mode 100644 index 0000000000..91a99b94e2 Binary files /dev/null and b/src/corelib/doc/snippets/resource-system/images/save.png differ diff --git a/src/corelib/doc/snippets/resource-system/main.cpp b/src/corelib/doc/snippets/resource-system/main.cpp new file mode 100644 index 0000000000..892f29d01d --- /dev/null +++ b/src/corelib/doc/snippets/resource-system/main.cpp @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2021 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation 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$ +** +****************************************************************************/ + +#include +#include +#include +#include +#include + +class DummyWidget : public QWidget { + Q_OBJECT + + QAction *cutAct; + + DummyWidget() { + //! [QAction] + cutAct = new QAction(QIcon(":/images/cut.png"), tr("Cu&t"), this); + //! [QAction] + } +}; + +int main() +{ +//! [url] + QQmlApplicationEngine engine; + engine.load(QUrl("qrc:/myapp/main.qml")); +//! [url] +} -- cgit v1.2.3