Uploaded image for project: 'Qt Design Studio'
  1. Qt Design Studio
  2. QDS-9808

CMake exporter loses commands for building Qt Quick Studio Components on 2nd run

    XMLWordPrintable

Details

    • QDS Berlin - 2023 Week 37/38

    Description

      Steps to reproduce

      1. Create a new project (General > Empty 1920x1080), targeting Qt 6.4
      2. Inspect the auto-generated CMake/C++ files
      3. Without making any changes, click "File" > "Export Project" > "Generate CMake Build Files..."
      4. Expand "Advanced Options" and check every available file
      5. Click "OK" to regenerate the CMake/C++ files
      6. Inspect the auto-generated CMake/C++ files

       

      Expected outcome

      Steps #2 and #6 should produce exactly the same files

       

      Actual outcome

      Steps #2 and #6 produce significantly different files. Crucially:

      • The commands required to build Qt Quick Studio Components and friends have disappeared
      • The qt_standard_project_setup() has disappeared
      • The install() command has disappeared
      • In <root>/content/CMakeLists.txt, `RESOURCES fonts/fonts.txt` has disappeared
      • Various parts have been rearranged, which causes noise for source control systems

       

      Here is the diff between #2 and #6:

      --- a/CMakeLists.txt
      +++ b/CMakeLists.txt
      @@ -1,46 +1,25 @@
      -cmake_minimum_required(VERSION 3.21.1)
      -
      -set(BUILD_QDS_COMPONENTS ON CACHE BOOL "Build design studio components")
      +cmake_minimum_required(VERSION 3.18)
       
       project(HelloQDSApp LANGUAGES CXX)
       
       set(CMAKE_INCLUDE_CURRENT_DIR ON)
       set(CMAKE_AUTOMOC ON)
       
      -find_package(QT NAMES Qt6 COMPONENTS Gui Qml Quick)
      -find_package(Qt6 REQUIRED COMPONENTS Core Qml Quick)
      -
      -# To build this application you need Qt 6.2.0 or higher
      -if (Qt6_VERSION VERSION_LESS 6.2.0)
      -message(FATAL_ERROR "You need Qt 6.2.0 or newer to build the application.")
      -endif()
      -
      -qt_add_executable(${CMAKE_PROJECT_NAME} src/main.cpp)
      +find_package(Qt6 COMPONENTS Gui Qml Quick)
      +qt_add_executable(HelloQDSApp src/main.cpp)
       
      -# qt_standard_project_setup() requires Qt 6.3 or higher. See https://doc.qt.io/qt-6/qt-standard-project-setup.html for details.
      -if (${QT_VERSION_MINOR} GREATER_EQUAL 3)
      -qt6_standard_project_setup()
      -endif()
      -
      -qt_add_resources(${CMAKE_PROJECT_NAME} "configuration"
      +qt_add_resources(HelloQDSApp "configuration"
           PREFIX "/"
           FILES
               qtquickcontrols2.conf
       )
       
      -target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE
      +target_link_libraries(HelloQDSApp PRIVATE
           Qt${QT_VERSION_MAJOR}::Core
           Qt${QT_VERSION_MAJOR}::Gui
           Qt${QT_VERSION_MAJOR}::Quick
           Qt${QT_VERSION_MAJOR}::Qml
       )
       
      -if (${BUILD_QDS_COMPONENTS})
      -    include(${CMAKE_CURRENT_SOURCE_DIR}/qmlcomponents)
      -endif ()
      -
       include(${CMAKE_CURRENT_SOURCE_DIR}/qmlmodules)
       
      -install(TARGETS ${CMAKE_PROJECT_NAME}
      -    BUNDLE DESTINATION .
      -    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
      diff --git a/asset_imports/CMakeLists.txt b/asset_imports/CMakeLists.txt
      new file mode 100644
      index 0000000..a50de6c
      --- /dev/null
      +++ b/asset_imports/CMakeLists.txt
      @@ -0,0 +1,3 @@
      +### This file is automatically generated by Qt Design Studio.
      +### Do not change
      +
      diff --git a/content/CMakeLists.txt b/content/CMakeLists.txt
      index 6811415..661440b 100644
      --- a/content/CMakeLists.txt
      +++ b/content/CMakeLists.txt
      @@ -1,13 +1,14 @@
       ### This file is automatically generated by Qt Design Studio.
       ### Do not change
       
      +
      +
       qt_add_library(content STATIC)
       qt6_add_qml_module(content
           URI "content"
           VERSION 1.0
           QML_FILES
      -        App.qml
               Screen01.ui.qml
      -    RESOURCES
      -        fonts/fonts.txt
      +        App.qml
      +
       )
      diff --git a/imports/HelloQDS/CMakeLists.txt b/imports/HelloQDS/CMakeLists.txt
      index 07235ea..4e52cf7 100644
      --- a/imports/HelloQDS/CMakeLists.txt
      +++ b/imports/HelloQDS/CMakeLists.txt
      @@ -1,18 +1,21 @@
       ### This file is automatically generated by Qt Design Studio.
       ### Do not change
       
      -qt_add_library(HelloQDS STATIC)
       set_source_files_properties(Constants.qml
           PROPERTIES
               QT_QML_SINGLETON_TYPE true
      -    )
      +)
      +
       
      +
      +qt_add_library(HelloQDS STATIC)
       qt6_add_qml_module(HelloQDS
      -	URI "HelloQDS"
      -	VERSION 1.0
      -	QML_FILES
      -		Constants.qml
      -		DirectoryFontLoader.qml
      -		EventListModel.qml
      -		EventListSimulator.qml
      +    URI "HelloQDS"
      +    VERSION 1.0
      +    QML_FILES
      +        EventListSimulator.qml
      +        EventListModel.qml
      +        DirectoryFontLoader.qml
      +        Constants.qml
      +
       )
      diff --git a/main.qml b/main.qml
      index 2c4f857..fa8f6d1 100644
      --- a/main.qml
      +++ b/main.qml
      @@ -1,8 +1,6 @@
      -/* This file is generated and only relevant for integrating the project into a Qt 6 and cmake based
      -C++ project. */
      -
       import QtQuick
       import content
       
       App {
       }
      +
      diff --git a/qmlmodules b/qmlmodules
      index 0179c58..3dbbdd9 100644
      --- a/qmlmodules
      +++ b/qmlmodules
      @@ -1,7 +1,7 @@
       ### This file is automatically generated by Qt Design Studio.
       ### Do not change
       
      -qt6_add_qml_module(${CMAKE_PROJECT_NAME}
      +qt6_add_qml_module(HelloQDSApp
           URI "Main"
           VERSION 1.0
           NO_PLUGIN
      @@ -10,8 +10,11 @@ qt6_add_qml_module(${CMAKE_PROJECT_NAME}
       
       add_subdirectory(content)
       add_subdirectory(imports)
      +add_subdirectory(asset_imports)
       
      -target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE
      +
      +target_link_libraries(HelloQDSApp PRIVATE
           contentplugin
           HelloQDSplugin
      +
       )
      diff --git a/src/app_environment.h b/src/app_environment.h
      index 6b42bff..0ede88a 100644
      --- a/src/app_environment.h
      +++ b/src/app_environment.h
      @@ -7,9 +7,10 @@
       
       void set_qt_environment()
       {
      -    qputenv("QT_AUTO_SCREEN_SCALE_FACTOR", "1");
      +    qputenv("QML_COMPAT_RESOLVE_URLS_ON_ASSIGNMENT", "1");
      +    qputenv("QT_QUICK_CONTROLS_CONF", ":/qtquickcontrols2.conf");
           qputenv("QT_ENABLE_HIGHDPI_SCALING", "0");
      +    qputenv("QT_AUTO_SCREEN_SCALE_FACTOR", "1");
           qputenv("QT_LOGGING_RULES", "qt.qml.connections=false");
      -    qputenv("QT_QUICK_CONTROLS_CONF", ":/qtquickcontrols2.conf");
      -    qputenv("QML_COMPAT_RESOLVE_URLS_ON_ASSIGNMENT", "1");
      +
       }
      diff --git a/src/import_qml_plugins.h b/src/import_qml_plugins.h
      index 6e6fa20..23748b5 100644
      --- a/src/import_qml_plugins.h
      +++ b/src/import_qml_plugins.h
      @@ -7,3 +7,4 @@
       
       Q_IMPORT_QML_PLUGIN(contentPlugin)
       Q_IMPORT_QML_PLUGIN(HelloQDSPlugin)
      +
      diff --git a/src/main.cpp b/src/main.cpp
      index 588b3a2..be43793 100644
      --- a/src/main.cpp
      +++ b/src/main.cpp
      @@ -5,13 +5,11 @@
       #include <QQmlApplicationEngine>
       
       #include "app_environment.h"
      -#include "import_qml_components_plugins.h"
       #include "import_qml_plugins.h"
       
       int main(int argc, char *argv[])
       {
           set_qt_environment();
      -
           QGuiApplication app(argc, argv);
       
           QQmlApplicationEngine engine;
      -- 
      

       

      Observations

      It's as if there are 2 different generators/templates in use. If this is the case, these generators/templates should be merged/refactored to reduce maintenance burden and prevent issues like this bug report.

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              thohartm Thomas Hartmann
              skoh-qt Sze Howe Koh
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes