Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt Creator, how do I add one c++ project to another?

Tags:

qt-creator

This seems like something that should be really simple, yet there doesn't seem to be a way to do it as one would expect.

I have two separate c++ projects open in qt creator, and I would like to include/compile against one project in the other.

Here's my layout:

project_a/
    project_a.pro
    someheaders.h
    somecode.cpp
    main.cpp

project_b/
     project_b.pro
     someheaders.h
     somecode.cpp
     main.cpp

Basically I want to be able to include the files from project_a in project b. I have set project_a to be a dependency within project_b but that seems to have been wholly ineffectual as a means of using the two projects. What do I do?

like image 494
john-charles Avatar asked Jun 01 '13 19:06

john-charles


People also ask

How do I add an external library to Qt?

Select Choose to open the Project Location dialog. In the Name field, give a name for the library. For example, mylib. Follow the instructions of the wizard until you get to the Project Management dialog.

Does Qt Creator support C?

In addition, the Qt Creator Bare Metal Device plugin provides support for the following compilers: IAREW is a group of C and C++ bare-metal compilers from the various IAR Embedded Workbench development environments. Note: Currently supported architectures are 8051 , AVR , ARM , STM8 , and MSP430 .

How do I create a project in Qt Creator?

Creating a project enables you to: Setting up a new project in Qt Creator is aided by a wizard that guides you step-by-step through the project creation process. The wizards prompt you to enter the settings needed for that particular type of project and create the necessary files for you.

How do I display files from the project folder in Qt?

Qt Creator determines whether to display files from the project folder in the Projects view depending on the file type (.pro, .pri, .cpp, .h, .qrc, and so on). To display other types of files, edit the project file. Add filenames as values of the DISTFILES variable.

Can I use Qt Creator without using qmake or QBs?

You can use wizards also to create plain C or C++ projects that use qmake, Qbs, or CMake, but do not use the Qt library. In addition, you can import projects as generic projects that do not use qmake, Qbs, or CMake. This enables you to use Qt Creator as a code editor and to fully control the steps and commands used to build the project.

How do I create a QMake project from a subproject?

However, the root project must specify that qmake uses the subdirs template to build the project. To create a root project, select File > New File or Project > Other Project > Subdirs Project > Choose. On the Summary page, select Finish & Add Subproject to create the root project and to add another project, such as a C++ library.


1 Answers

In order to open & build both project as one, use meta-project with type subdirs:

TEMPLATE = subdirs
SUBDIRS += project_a project_b
# Use ordered build, from first subdir (project_a) to the last (project_b):
CONFIG += ordered

You should put subproject any_name.pro to directory any_name, and place this directory next to meta-project .pro file.

If you want include headers from other project, write project_a.pri file that contains, for example:

# PWD expands to directory where project_a.pri placed.
INCLUDEPATH += $$PWD/
INCLUDEPATH += $$PWD/network

Than include this file to project_b.pro:

include(../project_a/project_a.pri)

If you want use project_a as library, change it to TEMPLATE = lib and add library with wizard, available in context menu when project_b.pro opened in editor.

like image 176
Sergey Shambir Avatar answered Sep 28 '22 04:09

Sergey Shambir