Important: Please read the Qt Code of Conduct -

Deep in the folder

  • Deep in the directory tree are my personal library-files and instead of writing the whole directory tree i.e.
    #include "C:\Dev\persoal\list\of\my\library\that\only\I\can\use\in\my\programs\myfile.h"
    I would rather just write:
    #include "myfile.h"

    Is there a way to tell Qt Creator [latest version, just downloaded] to add a new or another search directory?

  • Hi! Just add

    INCLUDEPATH += C:\Dev\persoal\list\of\my\library\that\only\I\can\use\in\my\programs

    to your *.pro file.

  • Lifetime Qt Champion


    To add to @Wieland, since you are using Qt, you should use forward slashes in your paths (the unix notation) that will avoid having to escape every backslashes.

  • @Wieland said:

    INCLUDEPATH += C:\Dev\persoal\list\of\my\library\that\only\I\can\use\in\my\programs

    Under the [INCLUDEPATH] is a file named i.e. "thunder.hpp". So the directory tree looks like this
    | ----- thunder.hpp {FILE}
    |----->Message {DIRECTORY}
    |-----message.hpp {FILE}
    |------message.cpp {FILE}

    Now, in my main.c, created by Qt Creator, I have include these files like this:
    #include "thunder.hpp"
    #include "Message/message.hpp"

    but this gives me an error saying:
    C:....\main.cpp:8: error: C1083: Cannot open include file: 'thunder.hpp': No such file or directory.

    But if I modify the code in main.c to look like this
    #include "C:\Dev\persoal\list\of\my\library\that\only\I\can\use\in\my\programs\thumder.hpp"
    then the program compiles.

    It seems to me that setting up the INCLUDEPATH variable in the .pro file fails to read the files under the INCLUDEPATH and it only reads the sub-directories under it. Is this the right assumption, or is there something wrong with my code?

    How can I solve this problem?

  • @Papa said:

    #include "thunder.hpp"
    #include "Message/message.hpp"

    Try to replace this by:

    #include <thunder.hpp>
    #include <Message/message.hpp>

  • tried it, but it did not work :(

  • Just tested it. Works for me. Clean the project and re-run qmake.

  • Nope, it does not work.

  • Lifetime Qt Champion

    Did you changed the backslashes to forward-slashes as SGaist suggested?
    So instead of C:\Dev\persoal\list\of\my\library\that\only\I\can\use\in\my\programs
    you should use C:/Dev/persoal/list/of/my/library/that/only/I/can/use/in/my/programs
    After this change delete the build directory and completely rebuild your project.

    Is the name of the header file really thunder.hpp? If Message/message.hpp is working then thunder.hpp should work as well.

Log in to reply