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
Forum Updated to NodeBB v4.3 + New Features

creating subfolders causes QML build issue

Scheduled Pinned Locked Moved Solved Qt Creator and other tools
8 Posts 3 Posters 753 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.
  • 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

                    • Login

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