Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. creating subfolders causes QML build issue

creating subfolders causes QML build issue

Scheduled Pinned Locked Moved Solved Qt Creator and other tools
10 Posts 5 Posters 1.8k Views 2 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.
  • mzimmersM Offline
    mzimmersM Offline
    mzimmers
    wrote on last edited by
    #1

    Hi all -

    My project has gotten large enough to merit breaking the code into subfolders. I took the following steps:

    • created a subfolder ("equipment")
    • moved two files into that subfolder
    • changed the reference in CMakeLists.txt to reflect that move
      When I build, I get an error, reported on a file in my build folder. The file is <myProjectName>_qmltyperegistrations.cpp, and the error is on this line:
    /****************************************************************************
    ** Generated QML type registration code
    **
    ** WARNING! All changes made in this file will be lost!
    *****************************************************************************/
    
    #include <QtQml/qqml.h>
    #include <QtQml/qqmlmoduleregistration.h>
    
    #include <activity.h>
    #include <activitymodel.h>
    #include <equipment.h>  // <== THIS LINE
    

    Which is a correct error message, but leaves me wondering how to deal with it. How does this file get generated?

    Thanks...

    mzimmersM 1 Reply Last reply
    0
    • mzimmersM mzimmers

      @Christian-Ehrlicher aargh...yes, I suppose so.

      I really didn't want to make a library anyway - the purpose of the subfolder was just to break up the main folder into smaller pieces. Oddly enough, I can't seem to find any documentation on how to do that.

      MesrineM Offline
      MesrineM Offline
      Mesrine
      wrote on last edited by
      #7

      @mzimmers You can do it as Christian says, with the library. If you do not want the library do not add a CMakelists.tx in the subfolder. Just reference the sources from the root CMakelists.txt like subfolder/equipment.cpp ...

      mzimmersM 1 Reply Last reply
      1
      • mzimmersM mzimmers

        Hi all -

        My project has gotten large enough to merit breaking the code into subfolders. I took the following steps:

        • created a subfolder ("equipment")
        • moved two files into that subfolder
        • changed the reference in CMakeLists.txt to reflect that move
          When I build, I get an error, reported on a file in my build folder. The file is <myProjectName>_qmltyperegistrations.cpp, and the error is on this line:
        /****************************************************************************
        ** Generated QML type registration code
        **
        ** WARNING! All changes made in this file will be lost!
        *****************************************************************************/
        
        #include <QtQml/qqml.h>
        #include <QtQml/qqmlmoduleregistration.h>
        
        #include <activity.h>
        #include <activitymodel.h>
        #include <equipment.h>  // <== THIS LINE
        

        Which is a correct error message, but leaves me wondering how to deal with it. How does this file get generated?

        Thanks...

        mzimmersM Offline
        mzimmersM Offline
        mzimmers
        wrote on last edited by
        #2

        I've tried converting the contents of my subfolder to a library, to see if that will work for me, even though it really isn't necessary.

        A header file in my subfolder includes a header file from the main folder. I added aline to the subfolder CMakeLists.txt file:

        target_include_directories(equipment PRIVATE
            "."
            ".." // <== this line added.
        )
        

        but, the included header contains an extern reference. At build time, I'm getting this error now:

        :-1: error: equipment/CMakeFiles/equipment.dir/equipment.cpp.obj:equipment.cpp:(.rdata$.refptr.INVALID_TEMP[.refptr.INVALID_TEMP]+0x0): undefined reference to `INVALID_TEMP'
        

        (INVALID_TEMP is the extern reference in the header file.)

        Any suggestions on how to fix this? Thanks...

        MesrineM 1 Reply Last reply
        0
        • mzimmersM mzimmers

          I've tried converting the contents of my subfolder to a library, to see if that will work for me, even though it really isn't necessary.

          A header file in my subfolder includes a header file from the main folder. I added aline to the subfolder CMakeLists.txt file:

          target_include_directories(equipment PRIVATE
              "."
              ".." // <== this line added.
          )
          

          but, the included header contains an extern reference. At build time, I'm getting this error now:

          :-1: error: equipment/CMakeFiles/equipment.dir/equipment.cpp.obj:equipment.cpp:(.rdata$.refptr.INVALID_TEMP[.refptr.INVALID_TEMP]+0x0): undefined reference to `INVALID_TEMP'
          

          (INVALID_TEMP is the extern reference in the header file.)

          Any suggestions on how to fix this? Thanks...

          MesrineM Offline
          MesrineM Offline
          Mesrine
          wrote on last edited by
          #3

          @mzimmers
          I recommend showing us some Cmakelists.txt, project structure, and some headers.
          But I think, your problem is related to C++ project structure.

          mzimmersM 1 Reply Last reply
          0
          • MesrineM Mesrine

            @mzimmers
            I recommend showing us some Cmakelists.txt, project structure, and some headers.
            But I think, your problem is related to C++ project structure.

            mzimmersM Offline
            mzimmersM Offline
            mzimmers
            wrote on last edited by
            #4

            @Mesrine project structure is simple: I have a top-level directory and two subfolders for QML. I'm trying to add a subfolder for C++ code.

            here's a portion of the subfolder's CMakeLists.txt file:

            cmake_minimum_required(VERSION 3.16)
            project(equipment)
            qt_add_library(equipment
                equipment.cpp equipment.h
            )
            
            set_target_properties(equipment PROPERTIES
                WIN32_EXECUTABLE TRUE
            )
            
            target_include_directories(equipment PRIVATE
                "."
                ".."
            )
            
            

            equipment.h has this line:

            #include "constants.h"
            

            which can be found in the main folder. It has this line:

            extern const float INVALID_TEMP;
            

            Which is defined in constants.cpp.

            Christian EhrlicherC 1 Reply Last reply
            0
            • mzimmersM mzimmers

              @Mesrine project structure is simple: I have a top-level directory and two subfolders for QML. I'm trying to add a subfolder for C++ code.

              here's a portion of the subfolder's CMakeLists.txt file:

              cmake_minimum_required(VERSION 3.16)
              project(equipment)
              qt_add_library(equipment
                  equipment.cpp equipment.h
              )
              
              set_target_properties(equipment PROPERTIES
                  WIN32_EXECUTABLE TRUE
              )
              
              target_include_directories(equipment PRIVATE
                  "."
                  ".."
              )
              
              

              equipment.h has this line:

              #include "constants.h"
              

              which can be found in the main folder. It has this line:

              extern const float INVALID_TEMP;
              

              Which is defined in constants.cpp.

              Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #5

              @mzimmers said in creating subfolders causes QML build issue:

              Which is defined in constants.cpp.

              Don't you think this source file shouldn't be compiled into the library then?

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

              mzimmersM 1 Reply Last reply
              1
              • Christian EhrlicherC Christian Ehrlicher

                @mzimmers said in creating subfolders causes QML build issue:

                Which is defined in constants.cpp.

                Don't you think this source file shouldn't be compiled into the library then?

                mzimmersM Offline
                mzimmersM Offline
                mzimmers
                wrote on last edited by
                #6

                @Christian-Ehrlicher aargh...yes, I suppose so.

                I really didn't want to make a library anyway - the purpose of the subfolder was just to break up the main folder into smaller pieces. Oddly enough, I can't seem to find any documentation on how to do that.

                MesrineM 1 Reply Last reply
                0
                • mzimmersM mzimmers

                  @Christian-Ehrlicher aargh...yes, I suppose so.

                  I really didn't want to make a library anyway - the purpose of the subfolder was just to break up the main folder into smaller pieces. Oddly enough, I can't seem to find any documentation on how to do that.

                  MesrineM Offline
                  MesrineM Offline
                  Mesrine
                  wrote on last edited by
                  #7

                  @mzimmers You can do it as Christian says, with the library. If you do not want the library do not add a CMakelists.tx in the subfolder. Just reference the sources from the root CMakelists.txt like subfolder/equipment.cpp ...

                  mzimmersM 1 Reply Last reply
                  1
                  • MesrineM Mesrine

                    @mzimmers You can do it as Christian says, with the library. If you do not want the library do not add a CMakelists.tx in the subfolder. Just reference the sources from the root CMakelists.txt like subfolder/equipment.cpp ...

                    mzimmersM Offline
                    mzimmersM Offline
                    mzimmers
                    wrote on last edited by
                    #8

                    @Mesrine yes, I think this is the best way to go for this app.

                    1. explicitly reference the subdirectories in the qt_add_executable() command.
                    2. do NOT use add_subdirectory() for this subdirectory.
                    3. do NOT use a CMakeLists.txt file in the subdirectory.
                    4. add this line to my target_include_directories() command:
                        "${PROJECT_SOURCE_DIR}/equipment"
                    

                    Seems to work.

                    Thanks to all for the help.

                    1 Reply Last reply
                    0
                    • mzimmersM mzimmers has marked this topic as solved on
                    • A Offline
                      A Offline
                      Alex777
                      wrote on last edited by Alex777
                      #9

                      This doesn't look good. The Qt's moc compiler can deal with source files located in the subfolders, and it even has -p, -f, -b files for fine grain controle. Then in the generated moc_MyClass.cpp it will put #include <subfolder/MyClass.h>
                      The qml module generator is less flexible though, and always generates #include <MyClass.h> which means I have to add subfolder to the target_include_directories. But this is not nice, because I like to have folder structure and having subfolder names in include directive increases readability.

                      SGaistS 1 Reply Last reply
                      0
                      • A Alex777

                        This doesn't look good. The Qt's moc compiler can deal with source files located in the subfolders, and it even has -p, -f, -b files for fine grain controle. Then in the generated moc_MyClass.cpp it will put #include <subfolder/MyClass.h>
                        The qml module generator is less flexible though, and always generates #include <MyClass.h> which means I have to add subfolder to the target_include_directories. But this is not nice, because I like to have folder structure and having subfolder names in include directive increases readability.

                        SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #10

                        @Alex777 hi,

                        That's something you should check the bug report system for and maybe open a discussion.

                        Interested in AI ? www.idiap.ch
                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                        1 Reply Last reply
                        0

                        • Login

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