Hello folks ,
First of all I want to thank the Code Blocks team for their valuable effort , so thank you for making code blocks a great IDE
.
You probably know that there is a template for making Qt applications in Code Blocks but unfortunately errors of the type
"Undefined reference to vtable" or something like that are generated when you use custom slots , this bothered me a little bit since I've been using CB for about 4 years and I'm very familiar with it , so I decided to make my own "solution".
Anyway , here is how I fixed the problem :
After opening CB , go to
Tools -> Configure Tools then click at
Add , choose a name for your new tool I simply called it MOC , specify the absolute path to moc.exe . Now the hardest part , in
Parameters put the following line :
${ACTIVE_EDITOR_FILENAME} -o moc_${ACTIVE_EDITOR_STEM}.cpp
ACTION_EDITOR_FILENAME is a macro that contains the file name of the currently active file and ACTIVE_EDITOR_STEM contains the same file name but without file extension.
Finally , in the 'Working directory' field , put ${PROJECT_DIR} and click Ok.
Now that our newly created tool is installed , how are we going to use it ?
Well , just create your Qt project using the template shipped with CB , as usual , now let's say you have a class called MyClass that contains custom slots , open MyClass.h then run the tool this will generate something like moc_MyClass.cpp , include it into MyClass.cpp and the work is done
.
I hope this little tutorial is useful .
Thank you for reading.
D-POWER