After building a 64-bit version of Qt with/for Microsoft Visual Studio, building a simple Qt test program and doing first steps with the CMake build system, the next hurdle appeared on the horizon in the form of support for Qt and its Q_OBJECT features (I am currently fighting more with the changes I made to my build environment than improving the actual program code…).
So, a looonng time of reading, testing, failing and cursing later, the following seems the way to go for my setup:
Tell CMake where to find the Qt files by adding this to the CMakeLists.txt; note that you have to be
very specific where it should look for those Qt5Config.cmake files; I first tried
C:/devel/ext/Qt/5.2.1/_64DLL/ — no luck:
set (CMAKE_PREFIX_PATH C:/devel/ext/Qt/5.2.1/_64DLL/lib/cmake)
CMAKE_AUTOMOC is a new feature since CMake 2.8.6, so that the Qt Meta Object Compiler (MOC) will automatically be called for those targets with Q_OBJECT/signals/slots.
set (CMAKE_INCLUDE_CURRENT_DIR ON) set (CMAKE_AUTOMOC ON) find_package(Qt5Core) [...]
With that being set, the required moc_*.cpp and *.moc files will be generated by CMake in the build directory; you don’t have to put them in the project’s original source code directory or add them to the file list in the CMakeLists.txt.
You then still have to modify your source code files, depending on where Q_OBJECT is used:
If Q_OBJECT is declared in the header file name.h, then add
#include "moc_name.cpp"in the corresponding implementation file name.cpp, preferably at the end of the file.
If Q_OBJECT is declared in the implementation file name.cpp, then add
#include "name.moc"to name.cpp itself, also preferably at the end.
Film & Television (25)
How To (41)
News & Announcements (22)
On Software (8)
Plans & Projects (8)