How to use multiple source directories

  • Hi All,
    I'm fairly new to QT but am enjoying using it. Most of my work is in C++ and i'd like to start using the QT IDE with all my older code.
    However I use multiple source directories and would like to keep it this way, for me it makes coding easier. It also allows me to have one source per project, but to have additional directories that are shared between projects, I could set these up as libs but don't want to for various reasons.
    So is there a way to tell QT to share directories for source. EG 2 projects below

    project A project B
    | |
    | |
    --------common file directory--------------
    | |
    | |
    -------graphics engine directory-----------
    | |
    | |
    source project A source project B


  • Sorry the output above isn't show directory set up correctly.... Project A and B share common and graphics directories, but each has it's own additional source and makefiles.

  • I don't know if this is the best way (may not be) but I use relative path names which works well for what I do.

    In the following example I have a folder called 'core' where I put everything I may potentially use in any project. In the folder for my application I have the Qt project file and subdirectories for everything related to the project (bin, res, src, ...) so it doesn't pollute the root of the project folder with lots of files.

    - expression.cpp
    - vector2.h
    - other_files.cpp
    SOURCES += 			src/main.cpp \
    					src/datawidget.cpp \
    					src/dataitemwidget.cpp \
    	   				../core/expression.cpp \
    					../core/vector3.cpp \
    					../core/other_files.cpp \
    - main.cpp
    #include "notes.h"
    #include "../../core/messagebox.h"
    #include "datawidget.h"

    It works for me. I suppose the next step might be to create library files for some of the more common items but leaving it in source code has some advantages (disadvantage is these common items are needlessly compiled over and over).

    Another method would be to change the search path options in your compiler to have it look in your alternate source folder location. It would make the #include directives a little easier to read.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.