fail to use Q_OBJECT Macro in CMake Project
-
Hi,
Did you already took a look at the CMake Manual from Qt's documentation ?
-
The problem is not CMake:
@Sewing said in fail to use Q_OBJECT Macro in CMake Project:
mainWindow.cpp: The file contains a Q_OBJECT macro
from http://doc.qt.io/qt-5/moc.html
The moc tool reads a C++ header file.
Did you declare a class with
Q_OBJECT
in a .cpp file? if so either yo do as the compiler tells you and#include "mainWindow.moc"
(this file name might change depending on how moc gets invoked) at the end of the file or, as I would recommend, move it into a header -
Then move the private declaration part in its own header that you only include in the implementation part.
Note that your MainWindow implementation looks a bit convoluted, you might be over-engineering some things.
-
@Sewing said in fail to use Q_OBJECT Macro in CMake Project:
pimpl idiom in which the nested implementation class in defined entirely within the source file
You can move it into a header file, Qt does it all the time, they use
_p.h
suffix to mark private headers. For example: QDateTimePrivate -
so if I understood correctly, the reason of having to do this is that the Q_OBJECT Macro has to be defined in the header file instead of the source file?
and after doing so, is the line
set_target_properties(${PROJECT_NAME} PROPERTIES AUTOMOC TRUE)
sufficient for invoking the MOC in my CMakeLists file?
-
@SGaist said in fail to use Q_OBJECT Macro in CMake Project:
Did you already took a look at the CMake Manual from Qt's documentation ?
@Sewing said in fail to use Q_OBJECT Macro in CMake Project:
I did
from http://doc.qt.io/qt-5/cmake-manual.html:
# Instruct CMake to run moc automatically when needed. set(CMAKE_AUTOMOC ON)