1

I like to include Qt project files to another Qt project. Long story short I've a production project and a test project. They're separate from each other to keep the production code clean.

I've tried add the headers and the sources with wildcard but it's not recursive.

SOURCES += path\to\production\*.cpp

After that I wrote a qmake logic to filter files.

QT += core
QT -= gui

TARGET = qt_test
CONFIG += console
CONFIG -= app_bundle

TEMPLATE = app

SOURCES = main.cpp

message("Fetching production code")

win32:PRODUCION_FILES = $$system(dir path\to\production /s /b)

for(a, PRODUCION_FILES) {

    IS_HEADER = $$find( a, .h$ )
    count( IS_HEADER, 1 ) {
        HEADERS += $$a
    }

    IS_CPP = $$find( a, .cpp$ )
    count( IS_CPP, 1 ) {
        SOURCES += $${a}
    }

    IS_FORM = $$find( a, .ui$ )
    count( IS_FORM, 1 ) {
        FORMS += $${a}
    }
}
message("Production code fetched!")
message(Headers: $$HEADERS)
message(Sources: $$SOURCES)
message(Forms: $$FORMS)

When the .pro file compiled the messages look fine:

Project MESSAGE: Fetching production code
Project MESSAGE: Production code fetched!
Project MESSAGE: Headers: path\to\production\mainwindow.h
Project MESSAGE: Sources: main.cpp path\to\production\main.cpp path\to\production\mainwindow.cpp
Project MESSAGE: Forms: path\to\production\mainwindow.ui

But somehow when I look at the Projects tab in the QtCreator I see all kinds of files for example in the Headers section (like cpp and ui and even pro).

What am I missing?

I use Qt 5.4.1 compiled with mingw4.9.2 64bit on a Win7 system in QtCreator 3.5.

I appreciate your suggestions and help.

Thanks, spiralfuzet

spiralfuzet
  • 75
  • 10
  • the way you add header files and other files differ i.e., `HEADERS += $$a` and `SOURCES += $${a}`. is it intentional? – ramtheconqueror Sep 16 '15 at 16:37
  • No but there is no difference " $$VAR => QMake variable's value at the time qmake is run $${VAR} => QMake variable's value at the time qmake is run (identical but enclosed to separate from surrounding text) $(VAR) => Contents of an Environment variable at the time Makefile (not qmake) is run $$(VAR) =>Contents of an Environment variable at the time qmake (not Makefile) is run" (from http://stackoverflow.com/questions/7754218/qmake-add-a-variable-into-the-pro-file) – spiralfuzet Sep 17 '15 at 06:14
  • You could always create another file with everything that is in common and `include` that file. – jwernerny Sep 17 '15 at 16:50
  • Yes, but I don't want to add anything manually. When I create a new class or file it is automatically added to the production .pro file. I don't want to add to another file, by hand. – spiralfuzet Sep 21 '15 at 10:05

0 Answers0