Qt 6.11 is out! See what's new in the release
blog
Testing app's CPP files
-
I have a project which looks like:
root.pro |- UI.pro | |- systemversion.cpp | `- systemversion.h `- TestUI.pro |- test_systemversion.cpp `- test_systemversion.hIn
TestUI.prothe configuration looks something like this:QT += testlib qmltest QT -= gui CONFIG += qt console warn_on depend_includepath testcase qmltestcase CONFIG -= app_bundle CONFIG += c++17 TEMPLATE = app INCLUDEPATH += ../UI DEPENDPATH += $${INCLUDEPATH} SOURCES += \ main.cpp \ test_systemversion.cpp HEADERS += \ test_systemversion.hWhen I run the build step I get this error:
undefined reference to `SystemVersion::SystemVersion(QObject*)This is happening because I am not able to link the library of
UI. I can't actually do that because UI is of typeTEMPLATE=appand this doesn't produce a shared object.How should I test those files when I can't link the shared object?
-
Then either add systemversion.cpp to your test sources or build a (static) lib inside UI.pro.
This lib can then be used to a) link to your test executable and b) together with a main.cpp to create the real executable.