News:

The new Release 25.03 is out! You can download binaries for Windows and many major Linux distros here .

Main Menu

Tutorial : How to configure Code Blocks to use it to develop Qt apps.

Started by D-POWER, October 02, 2010, 05:11:24 PM

Previous topic - Next topic

D-POWER

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



mictyd

Hey!

Your solution is really useful and, thanks! Unfortunately, using this tool can be bit annoying, maybe have you got any idea how to do it automatically? There is "pre/post build steps" tab in "build options", is there any way to use MOC (or however this tool we called) right before building without any user's interaction?

Regards,

Michał

rubypdf

[url=http://blog.rubypdf.com/2010/11/08/codeblocks-windows-setup-package-download-mirror/]Code::Blocks Windows setup package download mirror[/url]