### Set Install Example Directory Source: https://github.com/qt/qtbase/blob/dev/tests/manual/examples/widgets/mainwindows/mainwindow/CMakeLists.txt Defines the installation directory for the example. Ensure INSTALL_EXAMPLESDIR is set. ```cmake if(NOT DEFINED INSTALL_EXAMPLESDIR) set(INSTALL_EXAMPLESDIR "examples") endif() set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/mainwindows/mainwindow") ``` -------------------------------- ### Basic Qt Project Setup with CMake Source: https://github.com/qt/qtbase/blob/dev/tests/auto/cmake/test_wrap_cpp_in_subdir/CMakeLists.txt This CMakeLists.txt file sets up a basic Qt6 project. It finds the Qt6Core module and links an executable named 'example' to it. Ensure Qt6Core is installed and discoverable by CMake. ```cmake # Copyright (C) 2026 The Qt Company Ltd. # SPDX-License-Identifier: BSD-3-Clause cmake_minimum_required(VERSION 3.22) project(test_wrap_cpp_in_subdir) find_package(Qt6Core REQUIRED) add_executable(example main.cpp) target_link_libraries(example PRIVATE Qt::Core) add_subdirectory(subdir) ``` -------------------------------- ### Installation Configuration Source: https://github.com/qt/qtbase/blob/dev/tests/manual/examples/widgets/tutorials/addressbook/part6/CMakeLists.txt Configures the installation of the 'part6' executable, placing it in the specified example directory. ```cmake install(TARGETS part6 RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) ``` -------------------------------- ### Install Qt6 Executable Source: https://github.com/qt/qtbase/blob/dev/tests/manual/examples/widgets/tutorials/addressbook/part5/CMakeLists.txt Installs the built executable, bundle, and library to a specified directory within the examples installation path. This is used for distributing the application. ```cmake install(TARGETS part5 RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) ``` -------------------------------- ### Install Qt Executable and Resources Source: https://github.com/qt/qtbase/blob/dev/tests/manual/examples/widgets/tutorials/addressbook/part7/CMakeLists.txt Installs the built executable and related files to a specified directory within the examples directory. This command is used to package the application for distribution or deployment. ```cmake install(TARGETS part7 RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) ``` -------------------------------- ### CMake Project Setup for Vulkan Texture Example Source: https://github.com/qt/qtbase/blob/dev/tests/manual/examples/vulkan/hellovulkantexture/CMakeLists.txt Configures the CMake project, finds required Qt modules, and sets up the executable for the hellovulkantexture example. Ensure Qt6 is installed and accessible. ```cmake cmake_minimum_required(VERSION 3.16) project(hellovulkantexture LANGUAGES CXX) if(NOT DEFINED INSTALL_EXAMPLESDIR) set(INSTALL_EXAMPLESDIR "examples") endif() set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/vulkan/hellovulkantexture") find_package(Qt6 REQUIRED COMPONENTS Core Gui) qt_standard_project_setup() qt_add_executable(hellovulkantexture hellovulkantexture.cpp hellovulkantexture.h main.cpp ) set_target_properties(hellovulkantexture PROPERTIES WIN32_EXECUTABLE TRUE MACOSX_BUNDLE TRUE ) target_link_libraries(hellovulkantexture PRIVATE Qt6::Core Qt6::Gui ) ``` -------------------------------- ### Set Installation Directory Variables Source: https://github.com/qt/qtbase/blob/dev/tests/manual/findfiles/CMakeLists.txt Defines and sets variables for installation directories. `INSTALL_EXAMPLESDIR` defaults to 'examples' if not provided, and `INSTALL_EXAMPLEDIR` is derived from it. ```cmake if(NOT DEFINED INSTALL_EXAMPLESDIR) set(INSTALL_EXAMPLESDIR "examples") endif() set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/dialogs/findfiles") ``` -------------------------------- ### Install Executable and Libraries Source: https://github.com/qt/qtbase/blob/dev/tests/manual/findfiles/CMakeLists.txt Installs the 'findfiles' executable, bundle, and libraries to a specified directory within the examples installation path. This is used for distributing the application. ```cmake install(TARGETS findfiles RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) ``` -------------------------------- ### CMake Project Setup Source: https://github.com/qt/qtbase/blob/dev/tests/manual/examples/widgets/itemviews/pixelator/CMakeLists.txt Sets the minimum CMake version, project name, and languages. Defines installation directories for examples. ```cmake cmake_minimum_required(VERSION 3.16) project(pixelator LANGUAGES CXX) if(NOT DEFINED INSTALL_EXAMPLESDIR) set(INSTALL_EXAMPLESDIR "examples") endif() set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/itemviews/pixelator") ``` -------------------------------- ### Installation Configuration for Vulkan Texture Example Source: https://github.com/qt/qtbase/blob/dev/tests/manual/examples/vulkan/hellovulkantexture/CMakeLists.txt Configures the installation path for the hellovulkantexture executable and its associated files. This ensures the example is correctly placed when the project is installed. ```cmake install(TARGETS hellovulkantexture RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) ``` -------------------------------- ### Define Installation Directory Variable Source: https://github.com/qt/qtbase/blob/dev/tests/manual/examples/widgets/tutorials/addressbook/part7/CMakeLists.txt Sets the installation directory for examples, defaulting to 'examples' if not already defined. This variable is used later to specify where the application should be installed. ```cmake if(NOT DEFINED INSTALL_EXAMPLESDIR) set(INSTALL_EXAMPLESDIR "examples") endif() set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/tutorials/addressbook/part7") ``` -------------------------------- ### Qt Project Setup with CMake Source: https://github.com/qt/qtbase/blob/dev/tests/manual/examples/widgets/itemviews/storageview/CMakeLists.txt Configures the CMake minimum version, project name, and languages. Sets up installation directories. ```cmake cmake_minimum_required(VERSION 3.16) project(storageview LANGUAGES CXX) if(NOT DEFINED INSTALL_EXAMPLESDIR) set(INSTALL_EXAMPLESDIR "examples") endif() set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/itemviews/storageview") find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets) qt_standard_project_setup() ``` -------------------------------- ### Basic CMake Project Setup Source: https://github.com/qt/qtbase/blob/dev/examples/network/rsslisting/CMakeLists.txt Initializes a CMake project and specifies the minimum required version and project name. Ensure Qt6 is installed and discoverable by CMake. ```cmake cmake_minimum_required(VERSION 3.16) project(rsslisting LANGUAGES CXX) ``` -------------------------------- ### Basic CMake Project Setup Source: https://github.com/qt/qtbase/blob/dev/examples/widgets/widgets/shapedclock/CMakeLists.txt Sets up a new CMake project with Qt 6 support. Ensure Qt 6 is installed and discoverable by CMake. ```cmake cmake_minimum_required(VERSION 3.16) project(shapedclock LANGUAGES CXX) find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets) qt_standard_project_setup() ``` -------------------------------- ### Setting Installation Directories in CMake Source: https://github.com/qt/qtbase/blob/dev/tests/manual/examples/widgets/tools/plugandpaint/CMakeLists.txt Configures the installation directory for examples, ensuring it defaults to 'examples' if not already defined. This helps in organizing project outputs. ```cmake if(NOT DEFINED INSTALL_EXAMPLESDIR) set(INSTALL_EXAMPLESDIR "examples") endif() set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/tools/plugandpaint") ``` -------------------------------- ### Basic CMake Project Setup for Qt Source: https://github.com/qt/qtbase/blob/dev/examples/widgets/layouts/flowlayout/CMakeLists.txt Initializes a CMake project and finds required Qt6 components. Ensure Qt6 is installed and discoverable by CMake. ```cmake cmake_minimum_required(VERSION 3.16) project(flowlayout LANGUAGES CXX) find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets) ``` -------------------------------- ### Basic Qt6 Project Setup Source: https://github.com/qt/qtbase/blob/dev/examples/widgets/painting/basicdrawing/CMakeLists.txt Initializes a Qt6 project with C++ language support and finds necessary Qt modules. Ensure Qt6 is installed and discoverable by CMake. ```cmake cmake_minimum_required(VERSION 3.16) project(basicdrawing LANGUAGES CXX) find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets) qt_standard_project_setup() ``` -------------------------------- ### Build Qt OpenGL Context Info Example Source: https://github.com/qt/qtbase/blob/dev/tests/manual/examples/opengl/contextinfo/CMakeLists.txt Configures the build for the Qt OpenGL context info example using CMake. It sets up the project, finds required Qt modules, defines the executable, and specifies installation paths. ```cmake cmake_minimum_required(VERSION 3.16) project(contextinfo LANGUAGES CXX) if(NOT DEFINED INSTALL_EXAMPLESDIR) set(INSTALL_EXAMPLESDIR "examples") endif() set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/opengl/contextinfo") find_package(Qt6 REQUIRED COMPONENTS Core Gui OpenGL Widgets) qt_standard_project_setup() qt_add_executable(contextinfo main.cpp renderwindow.cpp renderwindow.h widget.cpp widget.h ) set_target_properties(contextinfo PROPERTIES WIN32_EXECUTABLE TRUE MACOSX_BUNDLE TRUE ) target_link_libraries(contextinfo PRIVATE Qt6::Core Qt6::Gui Qt6::OpenGL Qt6::Widgets ) install(TARGETS contextinfo RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) ``` -------------------------------- ### Basic CMake Project Setup for Qt Source: https://github.com/qt/qtbase/blob/dev/examples/widgets/mainwindows/menus/CMakeLists.txt Initializes a CMake project and finds the required Qt 6 components. Ensure Qt 6 is installed and discoverable by CMake. ```cmake cmake_minimum_required(VERSION 3.16) project(menus LANGUAGES CXX) find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets) ``` -------------------------------- ### Basic CMake Project Setup Source: https://github.com/qt/qtbase/blob/dev/examples/widgets/painting/imagecomposition/CMakeLists.txt Initializes a CMake project and specifies the minimum required version and project name. This is a standard starting point for CMake projects. ```cmake cmake_minimum_required(VERSION 3.16) project(imagecomposition LANGUAGES CXX) ``` -------------------------------- ### Basic CMake Project Setup for Qt6 Source: https://github.com/qt/qtbase/blob/dev/examples/widgets/dialogs/licensewizard/CMakeLists.txt Initializes a CMake project and finds the necessary Qt 6 components. Ensure Qt 6 is installed and discoverable by CMake. ```cmake cmake_minimum_required(VERSION 3.16) project(licensewizard LANGUAGES CXX) find_package(Qt6 REQUIRED COMPONENTS Core Gui PrintSupport Widgets) ``` -------------------------------- ### Basic CMake Project Setup for Qt6 Source: https://github.com/qt/qtbase/blob/dev/examples/gui/rasterwindow/CMakeLists.txt Initializes a CMake project and finds the necessary Qt6 components (Core and Gui). Ensure Qt6 is installed and discoverable by CMake. ```cmake cmake_minimum_required(VERSION 3.16) project(rasterwindow LANGUAGES CXX) find_package(Qt6 REQUIRED COMPONENTS Core Gui) ``` -------------------------------- ### Basic Qt6 Project Setup Source: https://github.com/qt/qtbase/blob/dev/tests/auto/cmake/test_qt_add_resources_rebuild/sample/CMakeLists.txt Initializes a CMake project with Qt6 support, requiring the Core module. This is the standard starting point for Qt projects using CMake. ```cmake cmake_minimum_required(VERSION 3.16) project(sample LANGUAGES CXX) find_package(Qt6 REQUIRED COMPONENTS Core) ``` -------------------------------- ### Basic CMake Project Setup Source: https://github.com/qt/qtbase/blob/dev/examples/widgets/animation/easing/CMakeLists.txt Initializes a CMake project and specifies the minimum required version and project name. This is a standard starting point for most CMake projects. ```cmake cmake_minimum_required(VERSION 3.16) project(easing LANGUAGES CXX) ``` -------------------------------- ### Basic CMake Project Setup Source: https://github.com/qt/qtbase/blob/dev/examples/widgets/painting/transformations/CMakeLists.txt Initializes a CMake project and specifies the minimum required version and project name. Ensure you have CMake 3.16 or later installed. ```cmake cmake_minimum_required(VERSION 3.16) project(transformations LANGUAGES CXX) ``` -------------------------------- ### Basic CMake Project Setup for Qt Source: https://github.com/qt/qtbase/blob/dev/examples/widgets/tutorials/modelview/4_headers/CMakeLists.txt This snippet sets up a new CMake project and finds the required Qt 6 components. Ensure Qt 6 is installed and discoverable by CMake. ```cmake cmake_minimum_required(VERSION 3.16) project(mv_headers LANGUAGES CXX) find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets) ``` -------------------------------- ### CMake Project Setup for Qt6 Source: https://github.com/qt/qtbase/blob/dev/tests/manual/examples/widgets/tutorials/addressbook/part5/CMakeLists.txt Configures a Qt 6 project with CMake, specifying the minimum required version and project name. Includes setting an installation directory for examples. ```cmake cmake_minimum_required(VERSION 3.16) project(part5 LANGUAGES CXX) ``` ```cmake if(NOT DEFINED INSTALL_EXAMPLESDIR) set(INSTALL_EXAMPLESDIR "examples") endif() set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/tutorials/addressbook/part5") ``` -------------------------------- ### Basic CMake Project Setup for Qt Source: https://github.com/qt/qtbase/blob/dev/examples/qtconcurrent/imagescaling/CMakeLists.txt Initializes a CMake project and finds required Qt 6 modules. Ensure Qt 6 is installed and discoverable by CMake. ```cmake cmake_minimum_required(VERSION 3.16) project(imagescaling LANGUAGES CXX) find_package(Qt6 REQUIRED COMPONENTS Concurrent Core Gui Network Widgets) ``` -------------------------------- ### Installing Qt6 Executable and Libraries Source: https://github.com/qt/qtbase/blob/dev/examples/qtestlib/tutorial2/CMakeLists.txt Installs the 'tutorial2' target, including the executable, runtime libraries, and bundle for macOS. This command defines where the built artifacts will be placed on the system. ```cmake install(TARGETS tutorial2 BUNDLE DESTINATION . RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ) ``` -------------------------------- ### Project and Qt Setup Source: https://github.com/qt/qtbase/blob/dev/tests/auto/cmake/tst_qaddpreroutine/CMakeLists.txt Configures the project name, version, language, and finds required Qt components. ```cmake cmake_minimum_required(VERSION 3.16) project(tst_qaddpreroutine LANGUAGES CXX VERSION "${project_version}" ) find_package(Qt6 COMPONENTS Core BuildInternals CONFIG REQUIRED) qt_prepare_standalone_project() find_package(Qt6 COMPONENTS GuiPrivate Test CONFIG REQUIRED) ``` -------------------------------- ### Basic Qt Project Setup Source: https://github.com/qt/qtbase/blob/dev/tests/auto/cmake/test_testlib_no_link_gui/CMakeLists.txt Sets up a basic Qt project, finds required Qt modules (Gui and Test), and includes necessary directories and definitions. This is a foundational snippet for most Qt CMake projects. ```cmake cmake_minimum_required(VERSION 3.16) project(no_link_gui) set(CMAKE_INCLUDE_CURRENT_DIR ON) if (EXISTS "${CMAKE_CURRENT_LIST_DIR}/FindPackageHints.cmake") include("${CMAKE_CURRENT_LIST_DIR}/FindPackageHints.cmake") endif() find_package(Qt6Gui REQUIRED HINTS ${Qt6Tests_PREFIX_PATH}) find_package(Qt6Test REQUIRED HINTS ${Qt6Tests_PREFIX_PATH}) include_directories( ${Qt6Gui_INCLUDE_DIRS} ${Qt6Test_INCLUDE_DIRS} ) add_compile_definitions( ${Qt6Gui_DEFINITIONS} ${Qt6Test_DEFINITIONS} ) ``` -------------------------------- ### Project Setup with CMake Source: https://github.com/qt/qtbase/blob/dev/cmake/tests/features/CMakeLists.txt Initializes a CMake project with version, description, and supported languages. Use this for basic project configuration. ```cmake cmake_minimum_required(VERSION 3.16) project(FeaturesTest VERSION 1.0.0 DESCRIPTION "QtFeature test" HOMEPAGE_URL "https://qt.io/" LANGUAGES CXX C ) ``` -------------------------------- ### Install StorageView Executable Source: https://github.com/qt/qtbase/blob/dev/tests/manual/examples/widgets/itemviews/storageview/CMakeLists.txt Installs the StorageView executable to a specified directory within the example installation path. ```cmake install(TARGETS storageview RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) ``` -------------------------------- ### Basic Qt6 Project Setup with CMake Source: https://github.com/qt/qtbase/blob/dev/examples/widgets/richtext/orderform/CMakeLists.txt This snippet sets up a new Qt6 project, finds required components (Core, Gui, Widgets), and establishes standard project settings. Ensure Qt6 is installed and discoverable by CMake. ```cmake cmake_minimum_required(VERSION 3.16) project(orderform LANGUAGES CXX) find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets) qt_standard_project_setup() ``` -------------------------------- ### Install Image Viewer Executable Source: https://github.com/qt/qtbase/blob/dev/tests/manual/examples/widgets/widgets/imageviewer/CMakeLists.txt Installs the image viewer executable to a specified directory within the examples path. ```cmake install(TARGETS imageviewer RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) ``` -------------------------------- ### Basic CMake Project Setup Source: https://github.com/qt/qtbase/blob/dev/tests/auto/cmake/test_multiple_find_package/CMakeLists.txt A minimal CMakeLists.txt file for a Qt project. Includes minimum required version, project name, finding Qt, and defining an executable. ```cmake cmake_minimum_required(VERSION 3.16) project(test_multiple_find_package) find_package(Qt6Core REQUIRED) add_subdirectory(subdir1) add_executable(exe1 main.cpp) target_link_libraries(exe1 Qt::Core) ``` -------------------------------- ### Install Puzzle Example Executable Source: https://github.com/qt/qtbase/blob/dev/tests/manual/examples/widgets/draganddrop/puzzle/CMakeLists.txt Installs the draganddrop_puzzle executable to a specified directory, handling runtime and bundle destinations. ```cmake install(TARGETS draganddrop_puzzle RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) ``` -------------------------------- ### Installation Rules Source: https://github.com/qt/qtbase/blob/dev/tests/manual/examples/widgets/itemviews/pixelator/CMakeLists.txt Specifies how the 'pixelator' target should be installed. It defines runtime, bundle, and library destinations relative to the example directory. ```cmake install(TARGETS pixelator RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) ``` -------------------------------- ### Install Executable Source: https://github.com/qt/qtbase/blob/dev/tests/manual/examples/widgets/effects/fademessage/CMakeLists.txt Installs the built executable and related files to a specified directory. This is typically used for deploying the example application. ```cmake install(TARGETS fademessage RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) ``` -------------------------------- ### Add Qt Example to Build System Source: https://github.com/qt/qtbase/blob/dev/examples/qtestlib/CMakeLists.txt Use this function to add a new example or tutorial to the Qt build system. Ensure the Qt6::Widgets target is available before calling. ```cmake if(NOT TARGET Qt6::Widgets) return() endif() qt_internal_add_example(tutorial1) ``` -------------------------------- ### Installation Rules for Executable Source: https://github.com/qt/qtbase/blob/dev/tests/manual/examples/widgets/mainwindows/dockwidgets/CMakeLists.txt Specifies how the 'dockwidgets' executable and its related files should be installed. RUNTIME and BUNDLE destinations are set relative to the example directory. ```cmake install(TARGETS dockwidgets RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) ``` -------------------------------- ### Qt 6 Package and Executable Setup Source: https://github.com/qt/qtbase/blob/dev/tests/manual/examples/widgets/itemviews/simplewidgetmapper/CMakeLists.txt Finds required Qt 6 components and sets up the main executable for the project. Links necessary Qt libraries. ```cmake find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets) qt_standard_project_setup() qt_add_executable(simplewidgetmapper main.cpp window.cpp window.h ) set_target_properties(simplewidgetmapper PROPERTIES WIN32_EXECUTABLE TRUE MACOSX_BUNDLE TRUE ) target_link_libraries(simplewidgetmapper PRIVATE Qt6::Core Qt6::Gui Qt6::Widgets ) ``` -------------------------------- ### Qt Calendar Example CMakeLists.txt Source: https://github.com/qt/qtbase/blob/dev/tests/manual/examples/widgets/richtext/calendar/CMakeLists.txt This is the main CMakeLists.txt file for the Qt Calendar example. It sets up the project, defines the executable, and specifies installation paths. ```cmake cmake_minimum_required(VERSION 3.16) project(calendar LANGUAGES CXX) if(NOT DEFINED INSTALL_EXAMPLESDIR) set(INSTALL_EXAMPLESDIR "examples") endif() set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/richtext/calendar") find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets) qt_standard_project_setup() qt_add_executable(calendar main.cpp mainwindow.cpp mainwindow.h ) set_target_properties(calendar PROPERTIES WIN32_EXECUTABLE TRUE MACOSX_BUNDLE TRUE ) target_link_libraries(calendar PRIVATE Qt6::Core Qt6::Gui Qt6::Widgets ) install(TARGETS calendar RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) ``` -------------------------------- ### Get Sub-image Starting Position and Spacing (libpng) Source: https://github.com/qt/qtbase/blob/dev/src/3rdparty/libpng/libpng-manual.txt These macros help in de-interlacing by providing the starting column and row, and the spacing between pixels for a given pass. ```c png_uint_32 x = PNG_PASS_START_COL(pass); png_uint_32 y = PNG_PASS_START_ROW(pass); png_uint_32 xStep = 1U << PNG_PASS_COL_SHIFT(pass); ``` -------------------------------- ### Installation Rules Source: https://github.com/qt/qtbase/blob/dev/examples/widgets/widgets/tablet/CMakeLists.txt Specifies how the 'qttablet' target should be installed on the system, including executable, library, and bundle destinations. Also generates and installs a deployment script. ```cmake install(TARGETS qttablet BUNDLE DESTINATION . RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ) qt_generate_deploy_app_script( TARGET qttablet OUTPUT_SCRIPT deploy_script NO_UNSUPPORTED_PLATFORM_ERROR ) install(SCRIPT ${deploy_script}) ``` -------------------------------- ### CMakeLists.txt for Dynamic Layouts Example Source: https://github.com/qt/qtbase/blob/dev/tests/manual/examples/widgets/layouts/dynamiclayouts/CMakeLists.txt This CMakeLists.txt file configures the build for the dynamic layouts example, specifying project details, Qt components, and installation paths. ```cmake cmake_minimum_required(VERSION 3.16) project(dynamiclayouts LANGUAGES CXX) if(NOT DEFINED INSTALL_EXAMPLESDIR) set(INSTALL_EXAMPLESDIR "examples") endif() set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/layouts/dynamiclayouts") find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets) qt_standard_project_setup() qt_add_executable(dynamiclayouts dialog.cpp dialog.h main.cpp ) set_target_properties(dynamiclayouts PROPERTIES WIN32_EXECUTABLE TRUE MACOSX_BUNDLE TRUE ) target_link_libraries(dynamiclayouts PRIVATE Qt6::Core Qt6::Gui Qt6::Widgets ) install(TARGETS dynamiclayouts RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) ``` -------------------------------- ### Begin and End Example Build Source: https://github.com/qt/qtbase/blob/dev/examples/CMakeLists.txt Marks the beginning and end of the build process for standalone examples. ```cmake qt_examples_build_begin(EXTERNAL_BUILD) ``` ```cmake qt_examples_build_end() ``` -------------------------------- ### Add Example to Qt Build System Source: https://github.com/qt/qtbase/blob/dev/examples/widgets/mainwindows/CMakeLists.txt Use this command to add a new example to the Qt build system. Ensure the example name is unique. ```cmake qt_internal_add_example(menus) ``` -------------------------------- ### Set up Qt MDI Project Source: https://github.com/qt/qtbase/blob/dev/tests/manual/examples/widgets/mainwindows/mdi/CMakeLists.txt Configures the CMake build system for the Qt MDI example. It sets the minimum required CMake version, project name, and installation directory for examples. ```cmake cmake_minimum_required(VERSION 3.16) project(mdi LANGUAGES CXX) if(NOT DEFINED INSTALL_EXAMPLESDIR) set(INSTALL_EXAMPLESDIR "examples") endif() set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/mainwindows/mdi") find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets) qt_standard_project_setup() ``` -------------------------------- ### Qt 6 Project Setup with CMake Source: https://github.com/qt/qtbase/blob/dev/examples/network/broadcastreceiver/CMakeLists.txt Configures a Qt 6 project using CMake. Ensure Qt 6 is installed and discoverable by CMake. This setup is standard for most Qt applications. ```cmake cmake_minimum_required(VERSION 3.16) project(broadcastreceiver LANGUAGES CXX) find_package(Qt6 REQUIRED COMPONENTS Core Gui Network Widgets) qt_standard_project_setup() ``` -------------------------------- ### Standard Project Setup Source: https://github.com/qt/qtbase/blob/dev/examples/corelib/mimetypes/mimetypebrowser/CMakeLists.txt Applies standard Qt6 project settings. This is a convenience macro provided by Qt. ```cmake qt_standard_project_setup() ``` -------------------------------- ### Install Qt Executable and Resources Source: https://github.com/qt/qtbase/blob/dev/examples/sql/sqlwidgetmapper/CMakeLists.txt Installs the built executable and related files to the appropriate directories based on the system's installation layout. This ensures the application can be deployed. ```cmake install(TARGETS sqlwidgetmapper BUNDLE DESTINATION . RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ) ``` -------------------------------- ### CMake Project Setup for Qt 6 Source: https://github.com/qt/qtbase/blob/dev/examples/dbus/remotecontrolledcar/CMakeLists.txt Configure your Qt 6 project using CMake. Ensure you have Qt 6 installed and its CMake configuration accessible. This setup is for a C++ project. ```cmake cmake_minimum_required(VERSION 3.16) project(remotecontrolledcar LANGUAGES CXX) ``` ```cmake find_package(Qt6 REQUIRED COMPONENTS Core DBus Gui Widgets) ``` ```cmake qt_standard_project_setup() ``` ```cmake add_subdirectory(car) add_subdirectory(controller) ``` -------------------------------- ### Build Embedded Dialogs Example with CMake Source: https://github.com/qt/qtbase/blob/dev/tests/manual/examples/widgets/graphicsview/embeddeddialogs/CMakeLists.txt This CMakeLists.txt file configures the build for the embeddeddialogs example. It sets up the project, finds Qt6 components, defines the executable, and handles resource compilation and installation. ```cmake cmake_minimum_required(VERSION 3.16) project(embeddeddialogs LANGUAGES CXX) if(NOT DEFINED INSTALL_EXAMPLESDIR) set(INSTALL_EXAMPLESDIR "examples") endif() set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/graphicsview/embeddeddialogs") find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets) qt_standard_project_setup() qt_add_executable(embeddeddialogs customproxy.cpp customproxy.h embeddeddialog.cpp embeddeddialog.h embeddeddialog.ui main.cpp ) set_target_properties(embeddeddialogs PROPERTIES WIN32_EXECUTABLE TRUE MACOSX_BUNDLE TRUE ) target_link_libraries(embeddeddialogs PRIVATE Qt6::Core Qt6::Gui Qt6::Widgets ) # Resources: set(embeddeddialogs_resource_files "No-Ones-Laughing-3.jpg" ) qt_add_resources(embeddeddialogs "embeddeddialogs" PREFIX "/" FILES ${embeddeddialogs_resource_files} ) install(TARGETS embeddeddialogs RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) ``` -------------------------------- ### CMake Project Setup for Qt Source: https://github.com/qt/qtbase/blob/dev/examples/network/dnslookup/CMakeLists.txt Basic CMake configuration for a Qt 6 project. Ensure Qt 6 is installed and discoverable by CMake. This setup is suitable for applications requiring Qt Core and Network modules. ```cmake cmake_minimum_required(VERSION 3.16) project(dnslookup LANGUAGES CXX) if (ANDROID) message(FATAL_ERROR "This project cannot be built on Android.") endif() find_package(Qt6 REQUIRED COMPONENTS Core Network) qt_standard_project_setup() ``` -------------------------------- ### Basic CMake Project Setup Source: https://github.com/qt/qtbase/blob/dev/examples/widgets/tutorials/modelview/2_formatting/CMakeLists.txt Initializes a CMake project and specifies the minimum required version and project name. Use this for any CMake-based project. ```cmake cmake_minimum_required(VERSION 3.16) project(mv_formatting LANGUAGES CXX) ``` -------------------------------- ### Basic Qt 6 CMake Project Setup Source: https://github.com/qt/qtbase/blob/dev/examples/qtestlib/tutorial3/CMakeLists.txt This CMake script sets up a Qt 6 project, finds necessary components, and defines an executable. Ensure Qt 6 is installed and discoverable by CMake. ```cmake cmake_minimum_required(VERSION 3.16) project(tutorial3 LANGUAGES CXX) find_package(Qt6 REQUIRED COMPONENTS Core Gui Test Widgets) qt_standard_project_setup() qt_add_executable(tutorial3 testgui.cpp ) set_target_properties(tutorial3 PROPERTIES WIN32_EXECUTABLE TRUE MACOSX_BUNDLE TRUE ) target_link_libraries(tutorial3 PRIVATE Qt6::Core Qt6::Gui Qt6::Test Qt6::Widgets ) install(TARGETS tutorial3 BUNDLE DESTINATION . RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ) qt_generate_deploy_app_script( TARGET tutorial3 OUTPUT_SCRIPT deploy_script NO_UNSUPPORTED_PLATFORM_ERROR ) install(SCRIPT ${deploy_script}) ``` -------------------------------- ### HTTP/1.1 If-Modified-Since Header Example Source: https://github.com/qt/qtbase/blob/dev/tests/testserver/apache2/testdata/www/htdocs/rfcs/rfc2616.html An example of the If-Modified-Since header field, specifying a date and time. This header is used with GET requests to conditionally retrieve resources, preventing unnecessary data transfer if the resource has not changed. ```http If-Modified-Since: Sat, 29 Oct 1994 19:43:31 GMT ``` -------------------------------- ### CMake Project Setup Source: https://github.com/qt/qtbase/blob/dev/examples/widgets/widgets/spinboxes/CMakeLists.txt Basic CMake configuration for a Qt6 project. Ensure Qt6 is installed and discoverable by CMake. ```cmake cmake_minimum_required(VERSION 3.16) project(spinboxes LANGUAGES CXX) find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets) qt_standard_project_setup() qt_add_executable(spinboxes main.cpp window.cpp window.h ) set_target_properties(spinboxes PROPERTIES WIN32_EXECUTABLE TRUE MACOSX_BUNDLE TRUE ) target_link_libraries(spinboxes PRIVATE Qt6::Core Qt6::Gui Qt6::Widgets ) install(TARGETS spinboxes BUNDLE DESTINATION . RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ) qt_generate_deploy_app_script( TARGET spinboxes OUTPUT_SCRIPT deploy_script NO_UNSUPPORTED_PLATFORM_ERROR ) install(SCRIPT ${deploy_script}) ``` -------------------------------- ### CMake Project Setup Source: https://github.com/qt/qtbase/blob/dev/examples/sql/cachedtable/CMakeLists.txt Initializes a CMake project and specifies the minimum required version and project name. Ensure Qt6 components are found. ```cmake cmake_minimum_required(VERSION 3.16) project(cachedtable LANGUAGES CXX) find_package(Qt6 REQUIRED COMPONENTS Core Gui Sql Widgets) qt_standard_project_setup() ``` -------------------------------- ### CMake Project Setup for Qt Standard Dialogs Source: https://github.com/qt/qtbase/blob/dev/examples/widgets/dialogs/standarddialogs/CMakeLists.txt Configures the CMake build system for a Qt 6 project. Ensure Qt 6 is installed and findable by CMake. This setup is for an executable that uses Core, Gui, and Widgets modules. ```cmake cmake_minimum_required(VERSION 3.16) project(standarddialogs LANGUAGES CXX) find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets) qt_standard_project_setup() qt_add_executable(standarddialogs dialog.cpp dialog.h main.cpp ) set_target_properties(standarddialogs PROPERTIES WIN32_EXECUTABLE TRUE MACOSX_BUNDLE TRUE ) target_link_libraries(standarddialogs PRIVATE Qt6::Core Qt6::Gui Qt6::Widgets ) install(TARGETS standarddialogs BUNDLE DESTINATION . RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ) qt_generate_deploy_app_script( TARGET standarddialogs OUTPUT_SCRIPT deploy_script NO_UNSUPPORTED_PLATFORM_ERROR ) install(SCRIPT ${deploy_script}) ``` -------------------------------- ### CMake Project Configuration Source: https://github.com/qt/qtbase/blob/dev/tests/manual/examples/widgets/widgets/imageviewer/CMakeLists.txt Sets up the minimum CMake version, project name, and installation directory for the image viewer example. ```cmake cmake_minimum_required(VERSION 3.16) project(imageviewer LANGUAGES CXX) ``` ```cmake if(NOT DEFINED INSTALL_EXAMPLESDIR) set(INSTALL_EXAMPLESDIR "examples") endif() set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/widgets/imageviewer") ``` -------------------------------- ### CMake Project Configuration Source: https://github.com/qt/qtbase/blob/dev/tests/manual/examples/widgets/tutorials/addressbook/part6/CMakeLists.txt Sets up the minimum CMake version, project name, and languages. Defines installation directories for examples. ```cmake cmake_minimum_required(VERSION 3.16) project(part6 LANGUAGES CXX) ``` ```cmake if(NOT DEFINED INSTALL_EXAMPLESDIR) set(INSTALL_EXAMPLESDIR "examples") endif() set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/tutorials/addressbook/part6") ``` -------------------------------- ### Qt6 Project Setup with CMake Source: https://github.com/qt/qtbase/blob/dev/examples/widgets/widgets/lineedits/CMakeLists.txt Standard CMake configuration for a Qt6 project. Ensure Qt6 is installed and discoverable by CMake. ```cmake cmake_minimum_required(VERSION 3.16) project(lineedits LANGUAGES CXX) find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets) qt_standard_project_setup() ``` -------------------------------- ### Qt Project Build and Installation Configuration Source: https://github.com/qt/qtbase/blob/dev/tests/manual/examples/widgets/tutorials/addressbook/part3/CMakeLists.txt Sets up standard Qt project properties and defines the installation directory for the executable and its bundles. ```cmake if(NOT DEFINED INSTALL_EXAMPLESDIR) set(INSTALL_EXAMPLESDIR "examples") endif() set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/tutorials/addressbook/part3") ``` ```cmake qt_standard_project_setup() ``` ```cmake qt_add_executable(part3 addressbook.cpp addressbook.h main.cpp ) ``` ```cmake set_target_properties(part3 PROPERTIES WIN32_EXECUTABLE TRUE MACOSX_BUNDLE TRUE ) ``` ```cmake target_link_libraries(part3 PRIVATE Qt6::Core Qt6::Gui Qt6::Widgets ) ``` ```cmake install(TARGETS part3 RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) ``` -------------------------------- ### CMake Project Setup Source: https://github.com/qt/qtbase/blob/dev/examples/corelib/bindableproperties/CMakeLists.txt Basic CMake configuration for a Qt project. Ensure Qt6 is installed and required components are found. ```cmake cmake_minimum_required(VERSION 3.16) project(bindableproperties LANGUAGES CXX) find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets) qt_standard_project_setup() ``` -------------------------------- ### Define and Install Custom Files Source: https://github.com/qt/qtbase/blob/dev/tests/auto/cmake/RunCMake/Sbom/custom_files/CMakeLists.txt This snippet demonstrates how to define custom files, their source files, and installation paths, including SBOM generation for custom files. ```cmake set(custom_files sources/custom1.txt ) set(custom_source_files sources/custom1_source.txt ) set(custom_install_path "custom") _qt_internal_add_sbom(CustomFiles TYPE CUSTOM ) _qt_internal_sbom_add_files(CustomFiles FILES "${custom_files}" SOURCE_FILES "${custom_source_files}" FILE_TYPE "CUSTOM" INSTALL_PATH "${custom_install_path}" INSTALL_PATH_DEBUG "${custom_install_path}/debug" INSTALL_PATH_RELEASE "${custom_install_path}/release" ) install( FILES ${custom_files} DESTINATION "${custom_install_path}" ) ``` -------------------------------- ### CMake Project Setup Source: https://github.com/qt/qtbase/blob/dev/examples/widgets/tutorials/widgets/windowlayout/CMakeLists.txt Basic CMake configuration for a Qt 6 project. Ensure Qt 6 is installed and discoverable by CMake. ```cmake cmake_minimum_required(VERSION 3.16) project(windowlayout LANGUAGES CXX) ``` -------------------------------- ### Install Qt Executable Source: https://github.com/qt/qtbase/blob/dev/tests/manual/examples/widgets/widgets/styles/CMakeLists.txt Installs the 'styles' executable, its bundle, and libraries to a specified directory within the installation path. ```cmake install(TARGETS styles RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) ``` -------------------------------- ### Qt 6 Package and Executable Setup Source: https://github.com/qt/qtbase/blob/dev/tests/manual/examples/widgets/widgets/imageviewer/CMakeLists.txt Finds the required Qt 6 components (Core, Gui, Widgets) and optionally PrintSupport. Creates the main executable for the image viewer. ```cmake find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets OPTIONAL_COMPONENTS PrintSupport ) qt_standard_project_setup() qt_add_executable(imageviewer imageviewer.cpp imageviewer.h main.cpp ) ``` ```cmake set_target_properties(imageviewer PROPERTIES WIN32_EXECUTABLE TRUE MACOSX_BUNDLE TRUE ) ``` ```cmake target_link_libraries(imageviewer PRIVATE Qt6::Core Qt6::Gui Qt6::Widgets ) ``` ```cmake if (TARGET Qt6::PrintSupport) target_link_libraries(imageviewer PRIVATE Qt6::PrintSupport) endif() ``` -------------------------------- ### CMake Project Setup Source: https://github.com/qt/qtbase/blob/dev/examples/widgets/itemviews/addressbook/CMakeLists.txt Basic CMake configuration for a Qt 6 project. Ensure Qt 6 is installed and discoverable by CMake. ```cmake cmake_minimum_required(VERSION 3.16) project(addressbook LANGUAGES CXX) ``` ```cmake find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets) ``` ```cmake qt_standard_project_setup() ```