creating subfolders causes QML build issue
-
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...
-
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...
-
@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.
-
@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?
-
@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.
-
@Mesrine yes, I think this is the best way to go for this app.
- explicitly reference the subdirectories in the qt_add_executable() command.
- do NOT use add_subdirectory() for this subdirectory.
- do NOT use a CMakeLists.txt file in the subdirectory.
- add this line to my target_include_directories() command:
"${PROJECT_SOURCE_DIR}/equipment"
Seems to work.
Thanks to all for the help.
-