User forums > General (but related to Code::Blocks)
Qt and undefined reference to ‘vtable
valkenar:
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.
Navigation
[0] Message Index
[*] Previous page
Go to full version