Author Topic: Qt and undefined reference to ‘vtable  (Read 31890 times)


  • Guest
Qt and undefined reference to ‘vtable
« on: March 09, 2007, 08:23:04 pm »
I need explicit instructions on using Code::Blocks with Qt Please.  :?

System Configuration:
-   Windows XP Pro
-   Qt 4.2.2
-   MinGW
-   Code::Blocks (Mar 7 2007, 16:52:13-wx2.6.3)

-   I’ve been writing C++ code for a while, but new to GUI’s
-   Have Qt working from command line (qmake, make, etc)
-   Have Qt working with (qmake –t vcapp, etc)
-   C::B new Qt project template works fine, as long as I don’t try to add other source files.

OK, when I try to add additional source files, they compile, but I get “undefined reference to ‘vtable for …’ when linking.  This has to do with not generating MOC file, etc.  How do I fix this.  I need explicit instructions please.

Another thing, is that if I include Qt classes that are not in QtGUI the includes are not found.  I can fix this by adding the paths to the cbp file. Is there a better way to take care of this?

Thanks so much for the help

Offline iw2nhl

  • Multiple posting newcomer
  • *
  • Posts: 116
  • BASIC, C, C++, Qt, bash
Re: Qt and undefined reference to ‘vtable
« Reply #1 on: March 10, 2007, 01:10:22 am »
- "undefined reference to ‘vtable for …"
after adding classes that inherit QObject and have Q_OBJECT functionalities (like signals and slots) you have to manually launch "qmake" (without any parameter), because it has to regenerate the makefile adding the calls to MOC files for the new classes.
- make the previous step easier using the QtWorkbench plugin,2253.0.html

Offline indigo0086

  • Almost regular
  • **
  • Posts: 150
Re: Qt and undefined reference to ‘vtable
« Reply #2 on: March 12, 2007, 04:41:40 pm »
Check to see if your destructor is implemented, I've gotten that before and it turned out to be the destructor being declared but not defined.  I hear it's quite common.


  • Guest
Re: Qt and undefined reference to ‘vtable
« Reply #3 on: March 13, 2007, 12:53:40 am »
Sounds like qtworkbench is for me.  However, after much work (setting up wxWidgets and codeblocks) I try to build qtworkbench (can't find a reference to a windows binary - sure would be nice) and get:

"Execution of 'zip -j9 ..\..\..\devel\share\codeblocks\ res\*.xrc' in 'C:\CodeBlocks\src\plugins\contrib\qtworkbench' failed."

I take it I need a zip (I have winzip and 7-zip), but which one?



Offline TDragon

  • Lives here!
  • ****
  • Posts: 936
    • Twilight Dragon Media
Re: Qt and undefined reference to ‘vtable
« Reply #4 on: March 13, 2007, 02:16:14 am »
I take it I need a zip (I have winzip and 7-zip), but which one?
Info-ZIP (latest Windows binary package available at Make sure the path to zip.exe is in your PATH environment variable. - TDM-GCC compiler suite for Windows (GCC 5.1.0 2015-06-28, 32/64-bit, no extra DLLs)

Offline valkenar

  • Single posting newcomer
  • *
  • Posts: 7
Re: Qt and undefined reference to ‘vtable
« Reply #5 on: March 17, 2007, 05:23:16 pm »
I'm not sure if this is the best way, but I have a system I use that runs moc automatically so I don't have to do it manually. There could definitely be a better way, but this works well.

For each header that declares a class with the Q_OBJECT macro (any class that with signals or slots), I configure the project to compile with a custom build option of "moc header.h -o moc_header.cpp" and add moc_header.cpp to the project.

Here are the steps to do it using the nightly build of march 16/2007. 

In the project management pane (the one that lists your project files) right click on the header file you want to set up.

Step 1:

Choose properties.
Go to the build tab
Make sure that "compile file" is checked but "link file" is not checked.
Go to the advanced tab
Make sure "choose custom command to build this file" is checked
In the text box, paste:
$(#QT)\bin\moc header.h -o moc_header.cpp
(replace header.h and moc_header.cpp with the name of your own headers)
Click okay

This assumes you have the global variable qt correctly set and that your version of QT has moc in the bin subdirectory.

Step 2
Create a new file
Choose to add it to the project
Save it as moc_header.cpp.

You'll never need to edit this file again, it is generated by moc, you just need to have it in the project and this is the easiest way.