Qt, CMake, Visual Studio and Q_OBJECT in cpp files

I am developing a large project using Qt 4.6, CMake 2.8, and Visual Studio 2008 for the Windows platform.

As long as the build system goes, all the standard things: I use the CMake macro QT4_WRAP_CPPto generate moc files from header files, which are then linked in the final executable in the command add_executable. Everything works as expected.

The only limitation with this setting is that I cannot define widgets or helpers using Q_OBJECTin .cpp files. This would be very convenient for small, context-sensitive helper classes that should appear next to where they are used.

I tried to transfer the entire list of source files (both .h and .cpp) to QT4_WRAP_CPP, and not just the header files, but this does not work (the link does not work because some characters associated with moc are undefined).

I think the problem is that for a given pair of foo.h and foo.cpp files, the macro QT4_WRAP_CPPwill generate the same moc file (moc_foo.cxx) in the same directory, and obviously this means that the first file will be overwritten second, and as a result, the characters will be absent during the link.

Is there a way to fix or work around this problem? For example, I tried to add a specific rule for the foo.cpp form

QT4_GENERATE_MOC(directory/foo.cpp directory/foo.moc)

and then add

#include "foo.moc"

foo.cpp. , , , , Visual Studio , .cpp ( ), , , Visual Studio.

, , - , QT4_WRAP_CPP_WITH_PREFIX, QT4_WRAP_CPP ( share/cmake-2.8/Modules/Qt4Macros.cmake), moc. , QT4_WRAP_CPP_WITH_PREFIX , .h .cpp . , , , CMake Qt, API.

?

Cheerz, Franz

+5
2

CMake "automoc", : http://blogs.kde.org/2011/11/01/cool-new-stuff-cmake-286-automoc

CMakeLists.txt:

set(CMAKE_AUTOMOC TRUE)

cpp (, example.cpp):

#include "example.moc"

(*.moc cpp).

+2

" MOC" (http://doc.qt.nokia.com/4.1/moc.html), "foo.moc" . , .pro , nokia.

+1

All Articles