HowTo: Qt4 and Code::Blocks on Wheezy

Share your wisdom. Not for support questions!

Moderator: How-to Curator

HowTo: Qt4 and Code::Blocks on Wheezy

Postby Sephiroth » August 29th, 2014, 5:35 pm

I struggled for months trying to make Code::Blocks work with Qt4 on Wheezy and tried dozens of tutorials. Nothing worked. I finally figured out that Qt4 is spread out in Wheezy, for unknown reasons. After that, I figured out how to properly configure C::B on my own. I am now sharing this knowledge because Qt4 and C::B is a POWERFUL combination.

First, you need to ste the environment variable for Qt4. DO this before creating a project or anything. To do this, click on "Settings" on the menu, then "Global Variables...". Now click the "New" button and create a new variable named "qt4". Set "/usr" for the "Base" field. For "include", use "/usr/share/qt4/include". For "lib", set "/usr/lib/x86_64-linux-gnu". Close the dialog. Now C::B can locate your Qt4 binaries!

Now create a Qt4 project. By default it will not build correctly. To build correctly, we need to use "qmake" from the Qt4 binaries. The following steps achieve this in C::B.

1) Go to Project->Properties...
2) Check the box "This is a custom Makefile"
3) Click on the "Project's build options..." button
4) Click on the top-most option in the tree on the left. This should be the name of your project!
5) Click on the "Pre/post build steps" tab
6) Paste the following text into the "Pre-build steps" box, being sure to replace "Project.pro" with your project name
Code: Select all
$(#qt4)/bin/qmake -project
printf "\\nCONFIG += debug_and_release\\n" >> Project.pro
printf "Debug:DESTDIR = bin/Debug\\nDebug:OBJECTS_DIR = obj/Debug/.obj\\nDebug:MOC_DIR = obj/Debug/.moc\\nDebug:RCC_DIR = obj/Debug/.rcc\\nDebug:UI_DIR = obj/Debug/.ui\\n" >> Project.pro
printf "Release:DESTDIR = bin/Release\\nRelease:OBJECTS_DIR = obj/Release/.obj\\nRelease:MOC_DIR = obj/Release/.moc\\nRelease:RCC_DIR = obj/Release/.rcc\\nRelease:UI_DIR = obj/Release/.ui\\n" >> Project.pro
$(#qt4)/bin/qmake -makefile Project.pro

7) Click on the "Make commands" tab
8) Select "Debug" on the left
9) Modify "Clean target/project" from "$make -f $makefile clean$target" to "$make -f $makefile $target-clean"
10) Select "Release" on the left and apply the changes you made to debug
11) Modify "Clean target/project" from "$make -f $makefile clean$target" to "$make -f $makefile $target-clean"
12) Click the OK button
13) Click on the "Build targets" tab
14) Highlight "Debug", click the "Rename" button, and rename it to "debug"
15) Now rename "Release" to "release"

Now you can simply use C::B as you normally would. The build and run options work as expected and call the Qt4 stuff to generate a proper makefile and everything is smooth. Enjoy using it!
Owyn: "This next one is a high elf sorceress or something, just get in close and stab her a few times, that'll teach her!"
Owyn: "I heard a rumor that you're an idiot. Is that true?"
Cicero: "Stab you, stab you, stab you!"
Psycho: "You sat in my swing, now I'm going to eat you!"
Psycho: "I think he's gonna' play xylophone with my spinal cord!"
Sephiroth
 
Posts: 387
Joined: February 22nd, 2011, 3:09 pm
Location: North Carolina

Return to HowTo

Who is online

Users browsing this forum: No registered users and 2 guests

x