I'm using Qt, CMake, and the VS2010 compiler. There seems to be a problem when I'm linking a small piece of test code. The linkers gives the following error:
plotter.cpp.obj : error LNK2001: unresolved external symbol "public: virtual str
uct QMetaObject const * __thiscall Plotter::metaObject(void)const " (?metaObject
@Plotter@@UBEPBUQMetaObject@@XZ)...
(it goes on for a while)
The error occurs when I'm trying to inherit from QObject in the following code:
class Plotter : public QObject
{
Q_OBJECT
public:
If I leave out the Q_OBJECT, the program links, but I can't use the class slots at runtime. I noticed that no moc file is generated for plotter.h. This is my CMakeLists.txt:
cmake_minimum_required (VERSION 2.6)
project (ms)
SET(CMAKE_BUILD_TYPE "Release")
FIND_PACKAGE(Qt4)
INCLUDE(${QT_USE_FILE})
ADD_DEFINITIONS(${QT_DEFINITIONS})
LINK_LIBRARIES(
${QT_LIBRARIES}
)
set(all_SOURCES plotter.cpp main.cpp dialog.cpp)
QT4_AUTOMOC(${all_SOURCES})
add_executable(ms ${all_SOURCES})
target_link_libraries(ms ${LINK_LIBRARIES})
A moc file is generated for dialog.cpp, but not for plotter.cpp, how is this possible?
Thanks!