Add subprojects to projects

You can link your application to Qt libraries and other libraries, such as system libraries or your own libraries. Further, your own libraries might link to other libraries. To compile your project and benefit from services such as code completion and syntax highlighting, add the libraries to your project. The process of adding a library to a project depends on the build system that you use.

CMake projects

To add CMakeLists.txt files to any project, use the add_subdirectory command. The files can define complete projects that you include into the top-level project or any other CMake commands.

qmake projects

When you create a new project and select qmake as the build system, you can add it to another project as a subproject in the Project Management dialog. However, the root project must specify that qmake uses the subdirs template to build the project.

To create a root project:

  1. Select File > New Project > Other Project > Subdirs Project > Choose.
  2. On the Summary page, select Finish & Add Subproject to create the root project and to add another project, such as a C++ library.

The wizard creates a project file (.pro) that defines a subdirs template and the subproject that you add as a value of the SUBDIRS variable. It also adds all the necessary files for the subproject.

Add subprojects to the root project

To create more subprojects, right-click the project name in the Projects view to open the context menu, and select New Subproject. Follow the steps in the New Subproject wizard to create a subproject.

{New Project dialog}

To add an existing project as a subproject, select Add Existing Projects in the context menu. In the file browser dialog, locate your subproject.

Remove subprojects

To remove subprojects, right-click the project name in the Projects view, and select Remove Subproject in the context menu.

Specify dependencies

To specify dependencies, use the Add Library wizard.

See also Creating Projects, Use project wizards, Add libraries to qmake projects, and Add libraries to CMake projects.

© 2024 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.