Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Migrating to CMake - adding resource files in Qt Creator

Migrating to CMake - adding resource files in Qt Creator

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
6 Posts 4 Posters 107 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Bob64
    wrote last edited by
    #1

    I have been working on a migration of a qmake-based project to CMake. I am not very experienced with CMake so bear with me.

    I used the migration tool to get me started. The project is not too complicated and that was more or less Ok to get things started.

    In the generated CMakeLists.txt file, all my resource files, including QML files were added in a set(qml_resource_files ...). This worked fine.

    Later, when syncing my project to other developments, I realised I was missing some new QML files that had been added recently to the qmake project. I added these in Qt Creator using the "Add Existing Files..." option from the project tree. However, I was still seeing runtime errors saying that the QML types I had added were "not a type". This was baffling because the QML files were clearly present in the project tree in the expected locations.

    When I examined the CMakeLists.txt, I found that Qt Creator had added the new QML files not to the qml_resource_files but had added them to the file list in qt_add_executable. Not only was this not consistent with what was already being done, but it did not work.

    Can anyone please explain what is happening here?

    In case it is relevant, I have a lot of QML files and they are arranged in a hierarchical directory structure. I use import "<relative directory path>" in my QML files to make other types available in the current file.

    Axel SpoerlA 1 Reply Last reply
    0
    • JoeCFDJ Offline
      JoeCFDJ Offline
      JoeCFD
      wrote last edited by
      #2

      Better to change to meson instead of cmake because cmake is slow.

      Christian EhrlicherC 1 Reply Last reply
      0
      • JoeCFDJ JoeCFD

        Better to change to meson instead of cmake because cmake is slow.

        Christian EhrlicherC Online
        Christian EhrlicherC Online
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote last edited by
        #3

        @JoeCFD said in Migrating to CMake - adding resource files in Qt Creator:

        Better to change to meson instead of cmake because cmake is slow.

        And how does this solve the problem? Only fud...

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        JoeCFDJ 1 Reply Last reply
        1
        • B Bob64

          I have been working on a migration of a qmake-based project to CMake. I am not very experienced with CMake so bear with me.

          I used the migration tool to get me started. The project is not too complicated and that was more or less Ok to get things started.

          In the generated CMakeLists.txt file, all my resource files, including QML files were added in a set(qml_resource_files ...). This worked fine.

          Later, when syncing my project to other developments, I realised I was missing some new QML files that had been added recently to the qmake project. I added these in Qt Creator using the "Add Existing Files..." option from the project tree. However, I was still seeing runtime errors saying that the QML types I had added were "not a type". This was baffling because the QML files were clearly present in the project tree in the expected locations.

          When I examined the CMakeLists.txt, I found that Qt Creator had added the new QML files not to the qml_resource_files but had added them to the file list in qt_add_executable. Not only was this not consistent with what was already being done, but it did not work.

          Can anyone please explain what is happening here?

          In case it is relevant, I have a lot of QML files and they are arranged in a hierarchical directory structure. I use import "<relative directory path>" in my QML files to make other types available in the current file.

          Axel SpoerlA Offline
          Axel SpoerlA Offline
          Axel Spoerl
          Moderators
          wrote last edited by
          #4

          @Bob64

          set(qml_resource_files ...) just assigns multiple files to a CMake variable. It doesn't do anything with the files though.

          Here is a standard CMake file that adds C++ executable, a QML module and resource files.

          cmake_minimum_required(VERSION 3.16) # Not really necessary, but I prefer to set a minimum standard
          
          project(MyProject VERSION 0.1 LANGUAGES CXX)  # Project name, version and languages
          
          set(CMAKE_CXX_STANDARD_REQUIRED ON)
          
          find_package(Qt6 REQUIRED COMPONENTS Quick QuickControls2)
          
          qt_standard_project_setup(REQUIRES 6.8)
          
          qt_add_executable(appMyProject # adds my main.cpp which then calls QML
              main.cpp
          )
          
          qt_add_resources(appMyProject
              "icons"
              PREFIX "/"
              FILES
                  arrow.svg # if you have multiple files, you might want to assign them to a variable
          )
          
          qt_add_qml_module(appMyProject
              URI MyProject
              QML_FILES
                  Main.qml
                  SOURCES qmlextension.h qmlextension.cpp
                  QML_FILES Anotherl.qml
                  QML_FILES EvenMore.qml
                  QML_FILES TheLast.qml
          )
          

          Software Engineer
          The Qt Company, Oslo

          1 Reply Last reply
          0
          • Christian EhrlicherC Christian Ehrlicher

            @JoeCFD said in Migrating to CMake - adding resource files in Qt Creator:

            Better to change to meson instead of cmake because cmake is slow.

            And how does this solve the problem? Only fud...

            JoeCFDJ Offline
            JoeCFDJ Offline
            JoeCFD
            wrote last edited by JoeCFD
            #5

            @Christian-Ehrlicher Do not try to solve the problem. Simply switch to meson. Cmake is messy and slow.

            I compared meson and cmake in build of gstreamer. meson is 10 times faster than cmake. Gstreamer has dropped cmake completely.

            Axel SpoerlA 1 Reply Last reply
            0
            • JoeCFDJ JoeCFD

              @Christian-Ehrlicher Do not try to solve the problem. Simply switch to meson. Cmake is messy and slow.

              I compared meson and cmake in build of gstreamer. meson is 10 times faster than cmake. Gstreamer has dropped cmake completely.

              Axel SpoerlA Offline
              Axel SpoerlA Offline
              Axel Spoerl
              Moderators
              wrote last edited by
              #6

              @JoeCFD said in Migrating to CMake - adding resource files in Qt Creator:

              @Christian-Ehrlicher Do not try to solve the problem. Simply switch to meson. Cmake is messy and slow.

              I compared meson and cmake in build of gstreamer. meson is 10 times faster than cmake. Gstreamer has dropped cmake completely.

              Even if true, it's unrelated to the post. It's a random unhelpful statement.

              Software Engineer
              The Qt Company, Oslo

              1 Reply Last reply
              1

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved