[CMake] Building a main.cpp containing a QObject subclass

Andreas Pakulat apaku at gmx.de
Mon Oct 31 06:57:27 EDT 2011


On 31.10.11 12:15:23, Laszlo Papp wrote:
> Hi,
> 
> I would like to achieve something like this by using cmake:
> http://doc.qt.nokia.com/4.8/activeqt-comapp.html
> 
> I would like to have a QObject subclass in my main.cpp file since it
> has just one method for instance, and thus it would be a convenient
> approach for me.

Three problems in your example:

a) for qt4_automoc (and presumambly the cmake-builtin moc-support) you
need to use the #include "moc_XXX..." form when the QObject class is in
a C++ implementation file. The #include "XXX.moc" version is for the
cases where the header contains the qobject class.

b) The FindQt4.cmake file developers decided to use .cxx as C++ file
extension, probably to avoid conflicts with existing files. So the above
needs to read #include "moc_XXX.cxx" for qt4_automoc to work

c) Your class declaration lacks the semicolon at its end.

With all those fixed the sample should compile.

Andreas



More information about the CMake mailing list