Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: mushakk on September 07, 2011, 03:13:20 pm

Title: How I use C::B and QT4
Post by: mushakk on September 07, 2011, 03:13:20 pm
Hi,

Yesterday I started a new project using QT4 and I found some problems trying to use it inside CodeBlocks and as I found several messages in this forum who have also had problems using QT and CB, I decided to create this post. I hope it will be useful for someone.

I apologize in advance if this information is already present in the wiki or forum, but I have not found it.

First I will say that this is a simple method (and not very comfortable) that will not help you with all issues but it works for me and maybe for you.

Note: The problem is that the default project does not invoke moc.

- First Create a QT4 project, enter project name and QT4 directory.
- Open a console, go to your project directory and execute 'qmake.exe -project'
- Add YourProject.pro (generated by qmake) to your project (to be able to edit it easily)
- Go to Project Settings and mark 'This is a custom makefile'
- Go to the tab 'Build Targets'
- Press button 'Dependencies...' then add YourProject.pro (generated by qmake) to 'External dependency files'
- Press button 'Build Options...' then select the top level project and write '$(#qt4)\bin\qmake' in the section 'Pre-build steps'
- Done

Unfortunately you will have to add the new code files to the file .PRO by hand but at least you can compile and debug C::B.

Another option is to run 'qmake.exe -project' every time you add a file...

As example, I make a little OpenGL sample. This is the aspect of the .PRO file:
Code
TEMPLATE = app
TARGET = ../bin/Sample2
DEPENDPATH += .
INCLUDEPATH += .

# Input
SOURCES += main.cpp GLWidget.cpp

HEADERS += GLWidget.h

QT += opengl

Note that in HEADERS you will have to add all files that inherit from QObject and/or want to use the SIGNAL/SLOT from QT.

PD: There is also a plugin called qtworkbench but I have not tried it because I found it later.

PD: I'm using Windows 7, C::B nightly build 7387. MinGW 4.5.2 and QT 4.7.4 (my own custom build because I'm using SJLJ MinGW from TDragon)

PD: I apologize for my bad English :(