Reputation: 709
I have trouble including QQmlEngine into a cmake project.
Here is my C++:
#include <QtQml/QQmlEngine>
...
QObject *someQObject;
QQmlEngine::setObjectOwnership(someQObject, QQmlEngine::ObjectOwnership::CppOwnership);
And the cmake part:
find_package(Qt5Core REQUIRED)
find_package(Qt5Gui REQUIRED)
find_package(Qt5Qml REQUIRED)
find_package(Qt5Quick REQUIRED)
...
add_executable(name ${src})
qt5_use_modules(name Core Gui Qml Quick )
Compilation fails with:
CMakeFiles/....cpp.o: In function `...':
....cpp:57: undefined reference to `QQmlEngine::setObjectOwnership(QObject*, QQmlEngine::ObjectOwnership)'
clang-3.8: error: linker command failed with exit code 1 (use -v to see invocation)
What am I missing?
Edit, @qCring (Sorry, can't comment your answer):
Well, everything works fine when I leave out the "setObjectOwnership" call. The rest of the Qt application works fine. Thus it is actually linking somehow.
When I add your line I get
"The plain signature for target_link_libraries has already been used with the target "name". All uses of target_link_libraries with a target must be either all-keyword or all-plain."
Edit:
My problem vanished somehow. I am running arch linux on x86_64.
Upvotes: 0
Views: 916
Reputation: 1442
You haven't actually linked to the Qt libraries and therefore get undefined symbol errors. Both macros, find_package
and qt5_use_modules
just provide CMake variables from certain packages/modules. You have to link the libraries like this:
target_link_libraries(${PROJECT_NAME} PUBLIC Qt5::Core PUBLIC Qt5::Gui PUBLIC Qt5::Quick PUBLIC Qt5::Qml)
Upvotes: 1