Author Topic: How to build Qt4 projects Using Code::Blocks?  (Read 7973 times)

Offline Marcelo

  • Single posting newcomer
  • *
  • Posts: 3
How to build Qt4 projects Using Code::Blocks?
« on: February 03, 2008, 09:27:05 pm »
Hi,

I'm trying to use C::B to develop using Qt4 on Linux and Windows. However, I couldn't get a project to build correctly yet.
First I tried to include:
qmake -project
qmake
make

as pre-build steps on project's build options. The project file and makefile are generated correctly and the software is built, but right after that C::B generates its own makefile and rebuilds the project, producing errors. The executable is built after the pre-build steps are run, but C::B thinks the build have failed, so I can't execute it via C::B neither I can debug it.
So I tried to check the option "This is a custom Makefile" at the project's properties dialog, but then the pre-build steps dialog is disabled and I can't enter the commands that generate the project file, the makefile and the executable.

Is there a way to build and debug Qt4 projects using C::B? Preferably using qmake's project file, so I can build the project in both Windows and Linux without changes?

Offline jmccay

  • Almost regular
  • **
  • Posts: 202
Re: How to build Qt4 projects Using Code::Blocks?
« Reply #1 on: February 03, 2008, 09:54:22 pm »
This is just an educated guess because I have never tried to compile a Qt app.  I know you can set the make under settings->Compiler & Debugger->under the Toolchain executable.  Before you change anything, I would recommend create a new compiler by copying it and renaming it test or something.  Then you should be able to change the make program.  I really don't know if it will work, but it is a starting point.  I am using an older build, but it might still be similar. 
OS: WinXP, Win98 SE, & sometimes Linux

a little light reading from the wxWidgets 2.6.2 readme: A detailed 2000-page reference manual is supplied in HTML, PDF and Windows Help form: see the docs hierarchy.

Offline vri

  • Multiple posting newcomer
  • *
  • Posts: 18
Re: How to build Qt4 projects Using Code::Blocks?
« Reply #2 on: February 04, 2008, 09:11:55 am »
You might consider using the Qtworkbench plugin, see
http://code.google.com/p/qtworkbench/ and http://forums.codeblocks.org/index.php/topic,2253.0.html.
However, this plugin does not install with the current nightly builds; you need to download an older one (before July 12, 2007, if I recall correctly), because the API has changed. The plugin developer is working on this.

Offline plegal

  • Single posting newcomer
  • *
  • Posts: 4
Re: How to build Qt4 projects Using Code::Blocks?
« Reply #3 on: February 05, 2008, 11:29:07 am »
Hi,

You can try this tutorial (it's in french but very graphic).

http://webmail.appert44.org/~plegal/index.php/Cr%C3%A9ation_de_projet_Qt_avec_Code::Blocks

It's easy to find the qt-prebuild script for windows (it was first written for windows).

Philippe 

Offline Marcelo

  • Single posting newcomer
  • *
  • Posts: 3
Re: How to build Qt4 projects Using Code::Blocks?
« Reply #4 on: February 10, 2008, 07:20:25 pm »
Thanks for all who helped. I've been experiencing with your suggestion and the current status is:

jmccay, I still need to run the regular make program to build the project. However, the makefile to be used must be the qmake generated makefile, which is created by those three commands I wrote about before. So, changing the make utility will not help, I just need the regular make to be run with the qmake generated makefile.

vri, I could not test this plugin yet. As far as I understood, it must be built together with Code::Blocks, right? I'm running a binary version package by my linux distribution and, if possible, I would like to keep it. It's a little difficult to locate the sources for the last linux version of codeblocks, most of the time the nightly releases are windows-only. However, if I can't find another solution, I'll give it a try.

Philippe, running the qt-prebuild script is almost the same as running "qmake -project; qmake; make" as pre-build steps. However, codeblocks insists on using it's own makefile to build the project, so it's necessary to add manualy the moc_*.cpp files to the project for each source file which has the Q_OBJECT directive. Not very practical but, if there's no other way, it will have to do.

I really would like that CodeBlocks would allow me to specify the commands I would like to execute to build the project without trying to do anything else by itself... However, there's no way to specify build commands when you select the custom makefile option. And if this option is not checked, it always tries to build the project by itself, leading to errors.

Thanks,

Marcelo

Offline vri

  • Multiple posting newcomer
  • *
  • Posts: 18
Re: How to build Qt4 projects Using Code::Blocks?
« Reply #5 on: February 10, 2008, 10:15:25 pm »
Marcelo,

I haven't explained well. The qtworkbench plugin can be used with a binary version of C::B. It is just that it cannot be used with a recent binary, it needs a binary from before the date at which the plugin SDK has changed. I checked, the date of change was July 6, 2007. I don't know your distro; if it is Ubuntu or Debian, you could download e.g. a binary from this link: http://forums.codeblocks.org/index.php/topic,6368.0.html.
I think the plugin does exactly what you require. Anyway, good luck.

Offline Marcelo

  • Single posting newcomer
  • *
  • Posts: 3
Re: How to build Qt4 projects Using Code::Blocks?
« Reply #6 on: February 10, 2008, 11:36:36 pm »
Hi, vri

I've read through the plugin wiki, but I found the binary version of the plugin for Windows only. For Linux, the install instructions says it has to be built together with codeblocks itself. I'm trying to avoid this, but if I find no other solution I'll try it and post the results here later. I'm using Fedora linux, which has code::blocks binary packages in its repositories. Thanks very much for the direct link for the last linux version of code::blocks which works with the plugin, this will help a lot.

[]'s
Marcelo

Offline yop

  • Regular
  • ***
  • Posts: 387
Re: How to build Qt4 projects Using Code::Blocks?
« Reply #7 on: February 13, 2008, 11:19:50 am »
Providing binary releases for linux is just too much work for me. I am using ubuntu and I could provide a binary release for ubuntu but still there could be incompatibilities. I remember a discussion with Yiannis about the way that third party plugins will be released (different distro specific packages with dependencies to codeblocks) but I don't know the status on that.
Life would be so much easier if we could just look at the source code.