Unsolved Project Management with subprojects: Accessing classes from another project
-
I am developing a large application that I wish to separate into 3 sub projects for organization and testing's sake; a model, a view, and a controller to act as a middle class between the two.
Here is the structure I have currently:
/Project | Project.pro |--- MODEL | |--- MODEL.pro | `--- ...source files |--- VIEW | |--- VIEW.pro | `--- ... source files |--- CONTROLLER | |--- CONTROLLER.pro | `--- ...source files
My Project.pro looks like this
TEMPLATE = subdirs SUBDIRS += \ VIEW \ CONTROLLER \ MODEL # where to find the sub projects VIEW.subdir = VIEW MODEL.subdir = MODEL CONTROLLER.subdir = CONTROLLER # what subproject depends on others CONTROLLER.depends = VIEW MODEL
I have a class MainWindow in VIEW. How can I add a reference to it in my CONTROLLER project so that I can use this MainWindow class in, for instance, the
main.cpp
in CONTROLLER? -
Hi @Smeeth,
first of all, you don't need these lines if you have a subdir/subdir.pro structure:
VIEW.subdir = VIEW
MODEL.subdir = MODEL
CONTROLLER.subdir = CONTROLLERHow can I add a reference to it in my CONTROLLER project so that I can use this MainWindow class in, for instance, the main.cpp in CONTROLLER?
Usually, each subproject generates a shared/static library or executable. So you would include the header file and link against the final library.
So your first choice would be, which of these projects generate libraries and which one the final exe? That also enforces the .depends line (the exe cannot be build before the libs).
Regards