Reputation: 12514
I have some previously written headers and I would like to include them in my Qt project. How can I do that without copying them in place?
After I added them with "Add Existing Files..." I can't seem to be able to #include my headers. Neither #include "header.h" nor #include "fullpath/header.h" works.
Upvotes: 2
Views: 11597
Reputation: 45665
You have to add an INCLUDEPATH
to your .pro file:
INCLUDEPATH += ...
Then you can include the header using #include <...>
syntax (not "..."
), since then the compiler searches for it in the include path rather than the current working directory which is your project's source folder.
Use the relative path of the header within your include path, not relative from within your project's source folder.
#include <header.h>
By the way, adding headers to your project is only needed when they are Qt headers using the Qt meta object system. The ones which define a QObject derived class are passed to the moc
, this is why a Qt project needs to specify the headers. The real compilation process doesn't need to know which headers are in your project (it just includes them when it sees a #include
directive).
Upvotes: 6