Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

c++ - Qt Creator how to run SUBDIRS projects

I've been using Qt Creator for a while now and my project is getting large enough that I'd like to move to using Qt's SUBDIRS template type to better organize my growing project.

The structure of my project is similar to the following

/master
 |--- master.pro
 `--- project1
 |    |--- project1.pro
 |    `--- ... (source files specific to project1)
 `--- project2
 |    |--- project2.pro
 |    `--- ... (source files specific to project2)
 `--- shared
      `--- ... (source files shared between project1 and project2)

Both project1 and project2 are separate independent projects, but that have some source/header files that they share for convenience and maintainability in the shared folder.

The bulk of my development time generally is spent working on the shared files and project1. So as I make changes to shared files both project1 and project2 must, in the end, be updated to work with these shared file.

My problem is, say I've just made changes to shared files AND project1 but have not yet updated project2. How do I, from QtCreator run project1 so I can test my changes? Obviously at the end of the day/week/month I'd fix project2 to work with these changes, but how would I run project1 in the mean time?

enter image description here

If I right-click on project1, it shows the "run" option. However, for this to work here, the entire "master.pro" has to be able to compile without errors.

I know as a workaround, I could just load project1.pro by itself, but I'd like to load master.pro and run it from the subproject.

Any help on this would be greatly appreciated.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Not all of my projects ready to run the code, how can I select one project to run, having subdir root project?

You can maintain several TEMPLATE = app projects to start parts of your code, say, unit tests for selected libraries as well as the entire app GUI starter. And try to isolate as much of shared code possible in TEMPLATE = lib types of projects. Whether the lib type of project needs to be a static library or dynamic with DEFINES += SHAREDLIB_LIBRARY is another question and the answer depends on how you distribute the app. I maintain my current subdir project with many dynamic libraries to prevent them being linked to executable all the time due to memory restrictions.

Open 'Projects' menu and make sure that Run Configuration points to your application project that contains main function and has:

# app.pro file contains
TEMPLATE = app

and also

# unit_test1.pro file contains
TEMPLATE = app

If some of your projects won't compile, exclude it from subdirs project:

TEMPLATE = subdirs
SUBDIRS = lib unit-test
# SUBDIRS = lib unit-test app # app not ready
# app.depends = lib # may exclude dependcies
unit-test.depends = lib

Mind 'Run configuration' choice of started projects below:

enter image description here

P.S. Don't forget to run qmake after project file changed.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...