I suggest that you put all sources and headers which both your main application project and your unit test project need into one .pri (.pro include) file. Put this file in the main project. Then include this file in both projects.
Note that whenever adding a new class to the main project, QtCreator automatically appends the SOURCES +=
and HEADERS +=
lines to the .pro file, but you want them to be in the .pri file, so you need to move them afterwards manually. I think that there is no solution to tell QtCreator where to put them.
Main project:
myproject.pro
myproject.pri
main.cpp
someclass.h
someclass.cpp
myproject.pro:
QT += ...
TARGET = ...
...
SOURCES += main.cpp # "private" to this project
include(myproject.pri) # needed in unit test
myproject.pri:
SOURCES += someclass.cpp
HEADERS += someclass.h
Unit test project:
unittest.pro
main.cpp
test.h
test.cpp
unittest.pro:
QT += ...
TARGET = ...
...
SOURCES += main.cpp test.cpp
HEADERS += test.h
# include the classes from the main project:
INCLUDEPATH += ../myproject/
include(../myproject/myproject.pri)