Aleanar
Aleanar

Reputation: 119

QTCreator : Use qt project into another

I was wondering how to use a QT Project into another in QTCreator. I've created a subdirs test project with this hierarchy :

MainProject
  MainProject.pro
  ConsoleSubProject
    ConsoleSubProject.pro
    main.cpp
    firstclass.hpp
    firstclass.cpp
  GuiSubProject
    GuiSubProject.pro
    main.cpp
    mainwindow.hpp
    mainwindow.cpp

I would like to use the class "firstclass" (ConsoleSubProject) in GuiSubProject. To do so, I've added this line in GuiSubProject.pro :

include(../ConsoleSubProject/ConsoleSubProject.pro)

When I've tried to build the project, it give me errors :

MainProject/GuiSubProject/mainwindow.hpp:4: error: QMainWindow: No such file or directory

If you have any idea about how can I use the class of project into another ?

Regards

Upvotes: 6

Views: 4196

Answers (2)

Kirween
Kirween

Reputation: 1538

You can do something like this:

MainProject/common.pri

    INCLUDEPATH  += $$PWD/ConsoleSubProject
    SOURCES      += $$PWD/ConsoleSubProject/firstclass.cpp
    HEADERS      += $$PWD/ConsoleSubProject/firstclass.hpp

MainProject/ConsoleSubProject/ConsoleSubProject.pro

    include(../common.pri)
    QT += core
    SOURCES      += main.cpp

MainProject/GuiSubProject/GuiSubProject.pro

    include(../common.pri)
    QT += core gui
    SOURCES      += main.cpp mainwindow.cpp
    HEADERS      += mainwindow.hpp

Upvotes: 5

Tylor Steinberger
Tylor Steinberger

Reputation: 1

Instead of include(../.....) in your GuiSubProject.pro its should be

    INCLUDEPATH    = ../ConsoleSubProject

Upvotes: 0

Related Questions