Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to use multiple source directories

How to use multiple source directories

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tony67
    wrote on last edited by
    #1

    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

    Thanks

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tony67
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • R Offline
        R Offline
        Rondog
        wrote on last edited by
        #3

        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.

        Example:
        [core]
        - expression.cpp
        - vector2.h
        - other_files.cpp
        ==========
        [project]
        - project.pro
        {
        SOURCES += 			src/main.cpp \
        					src/datawidget.cpp \
        					src/dataitemwidget.cpp \
        	   				../core/expression.cpp \
        					../core/vector3.cpp \
        					../core/other_files.cpp \
        					...
        }
        [project/src]
        - 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.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved