[Qt-creator] Classes common to different sub-projects

Coda Highland chighland at gmail.com
Fri Mar 28 01:01:33 CET 2014

On Thu, Mar 27, 2014 at 4:25 PM,  <qt.dantec at free.fr> wrote:
> Hi list !
> I have 3 programs that interact with each other and share several
> classes (2 on the same computer, the third on a distant server).
> When a change occur in one of these classes, I want to recompile
> automatically the programs that are impacted.
> How to do that in QtCreator ?
> I always assumed that this was why QtCreator supported the concept of
> sub-projects, but it appears that I cannot create a class at the level
> of the root project, to share among the sub-projects.
> Thanks guys for any pointer.
> Quentin

There's nothing prohibiting you from simply including the files in
each of the subprojects. One way to do this, such that the project
configuration doesn't need duplicated, is to create a .pri file that
refers to the headers and sources of the shared classes and then
include it from within the other projects' .pro files.

Alternatively, you can make the common code a fourth subproject that
generates a static library, and make the other three depend on it.
This isn't quite 100% portable as dependency tracking like this
requires that the build tool supports it (make does, but not all build
backends supported by qmake do), but it does work, and qmake is smart
enough to make the Makefile include .h dependencies.

/s/ Adam

More information about the Qt-creator mailing list