(→Solution for "undefined reference to `vtable for MainWindow'": new section) |
(→Solution for "undefined reference to `vtable for MainWindow'") |
||
| Line 29: | Line 29: | ||
This fixed the problem for me. Please try this and post your results so I can correct the tutorial. | This fixed the problem for me. Please try this and post your results so I can correct the tutorial. | ||
| + | |||
| + | : You shouldn't need to use <tt>qt4_automoc()</tt> at all. With the code copied verbatim from the tutorial it builds just fine. The <tt>kde4_add_executable()</tt> does all that magic itself. According to Thiago, "If kde4automoc [<em>which is called by kde4_add_executable() I believe</em>] finds a header with Q_OBJECT whose .moc isn't included anywhere, it'll include that from a .cpp" --[[User:Milliams|milliams]] 16:02, 14 April 2008 (CEST) | ||
When compiling, cmake failed during the linking process.
undefined reference to `vtable for MainWindow'
I received this error, after making one tiny mistake: I named my headerfile
mainwindow.hpp
instead of
mainwindow.h
Once renamed, everything should work fine.
Tiny hint: if you quickly want to copy the source displayed in this tutorial, but are as annoyed as I am about the line numbering which is copied as well, use the edit function of this site to access the (barebone) sourcecode.
When I tried to compile the code, I got the same error:
undefined reference to `vtable for MainWindow'
This is because you have to change CMakeLists.txt in order to generate .moc files. Just add this line:
qt4_automoc(${tutorial4_SRCS})
Then you also have to add this line at the bottom of mainwindow.cpp:
#include "mainwindow.moc"
This fixed the problem for me. Please try this and post your results so I can correct the tutorial.