Talk:Development/Tutorials/Saving and loading: Difference between revisions

From KDE TechBase
(Added the necessary line for the vtable fix)
No edit summary
 
(4 intermediate revisions by 2 users not shown)
Line 5: Line 5:
</code>
</code>


Simply add the following line to the mainwindow.cpp:
I received this error, after making one tiny mistake: I named my headerfile
<code>
<code>mainwindow.hpp</code>
#include "mainwindow.moc"
instead of
</code>
<code>mainwindow.h</code>
Once renamed, everything should work fine.


Also add this line to your CMakeLists.txt near the top:
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.
<code>
: I just tested this with Konq, Firefox and Opera and none of them copied the line numbering. What browser are you using? --[[User:Milliams|milliams]] 15:00, 22 March 2008 (CET)
include (KDE4Defaults)
</code>


I don't exactly know why this happens to me, but I suspect the fact that I have not built any special environment for working on KDE4 applications (as described [[Getting_Started/Set_up_KDE_4_for_development#KDevelop|here]].
== Solution for "undefined reference to `vtable for MainWindow'" ==


Can someone who understands the process please add the appropriate steps to the main tutorial?
When I tried to compile the code, I got the same error:
 
<code>undefined reference to `vtable for MainWindow'</code>
 
This is because you have to change CMakeLists.txt in order to generate .moc files. Just add this line:
 
<code>qt4_automoc(${tutorial4_SRCS})</code>
 
Then you also have to add this line at the bottom of mainwindow.cpp:
 
<code>#include "mainwindow.moc"</code>
 
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)
 
:: Thank you very much. I used the KDevelop cmake template to create my project and the CMakeLists.txt used add_executable() instead of kde4_add_executable(). Problem solved :-) --[[User:Simonknight6600|Simon Schweiger]] 18:18, 14 April 2008 (CEST)

Latest revision as of 16:18, 14 April 2008

Compiling failed due to 'undefined reference to vtable ...'

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.

I just tested this with Konq, Firefox and Opera and none of them copied the line numbering. What browser are you using? --milliams 15:00, 22 March 2008 (CET)

Solution for "undefined reference to `vtable for MainWindow'"

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.

You shouldn't need to use qt4_automoc() at all. With the code copied verbatim from the tutorial it builds just fine. The kde4_add_executable() does all that magic itself. According to Thiago, "If kde4automoc [which is called by kde4_add_executable() I believe] finds a header with Q_OBJECT whose .moc isn't included anywhere, it'll include that from a .cpp" --milliams 16:02, 14 April 2008 (CEST)
Thank you very much. I used the KDevelop cmake template to create my project and the CMakeLists.txt used add_executable() instead of kde4_add_executable(). Problem solved :-) --Simon Schweiger 18:18, 14 April 2008 (CEST)