Author Topic: Tutorial : How to configure Code Blocks to use it to develop Qt apps.  (Read 14479 times)

D-POWER

  • Guest
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 :

Code
${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


« Last Edit: October 03, 2010, 10:22:20 pm by D-POWER »

mictyd

  • Guest
Re: Tutorial : How to configure Code Blocks to use it to develop Qt apps.
« Reply #1 on: October 11, 2010, 09:12:40 pm »
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ł

Offline rubypdf

  • Single posting newcomer
  • *
  • Posts: 4
    • RubyPDF
Re: Tutorial : How to configure Code Blocks to use it to develop Qt apps.
« Reply #2 on: November 10, 2010, 08:17:21 am »
Why not use QtCreator to develop QT apps?