In order to organize larger Qt projects, I usually create subdirectories to hold different “components” of the project. For instance, I like to extend Qt’s QLineEdit
into my own DateLine
class which is a QLineEdit
with some additional bells & whistels such as checking if a valid date has been entered. These little helper classes are held in a project subdirectory called – guess what… – Helpers. Whenever I ran a build, Qt complained that my class header could not be found (“dateline.h: No such file or directory
“).
Although the #include
command in the relevant cpp source file is complete, the headers are correctly listed in the HEADERS
section of the pro file and intellitype finds the correct paths, Qt Designer fails to apply the full path in its auto-generated ui_***.h files for the different UI elements.
The only workaround I found so far was by manually completing the #include directives in each ui_***.h file where the compiler stopped. As there were quite a few helper classes and quite a few UI elements in my project and it had to be done after each fresh build, these were hours wasted in manual corrections.
After searching around, I finally found the reason in this post on stackexchange: In your pro file, you have to add your subdirectory to the INCLUDEPATH variable. So a simple additional line like
1 |
INCLUDEPATH += Helpers |
will do the trick.