Django
Django

Reputation: 381

Qt 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?

A simple "#include mainwindow.h" does not suffice. as I get a "No such file or directory". Is there a way to explicitly point it towards the class of another object? Do I have to add a dependency somewhere in the project files?

Upvotes: 2

Views: 564

Answers (2)

Jaa-c
Jaa-c

Reputation: 5157

In each of your pro file, setup your includepath like this:

INCLUDEPATH += $$PWD/..

Then, you can include files like

#include "VIEW/mainwindow.h"

Also if you will build subprojects to separate dll files, you will have to add dependecy of the dll like this:

LIBS += -lView

Also note that most likely, you should include controller to your view, not the other way around.

Upvotes: 1

chodzikman
chodzikman

Reputation: 9

Are your dependent projects libraries? I am not sure, but this feature might be intended to use it only with dynamic linkage.

See TEMPLATE = lib examples in Qt documentation

Upvotes: 0

Related Questions