Author Topic: Using C::B to build Qt applications  (Read 9509 times)

Offline Michael

  • Lives here!
  • ****
  • Posts: 1608
Using C::B to build Qt applications
« on: March 31, 2006, 05:14:26 pm »
Hello,

I have just converted a Qt project from Visual Studio .NET 2003 to Code::Block. So, I would like to share my experience. May be it could be useful to other users :).

The project was relatively simple: main.cpp (main application file), CDITool.h, CDITool.cpp and CDIToolDefault.ui (user interface file. Created by the Qt Designer).

Please note that this case concerns the conversion of an already existing Qt project. The CDITool class is derived from CDIToolDefault class "automatically created" by Qt Designer. The creation of a derived class was a necessary step, because all changes made in the CDIToolDefault class files will be lost. 

I am using C::B rev2285, MinGW with GCC 4.1.0 and Qt 3.3.4 (independent version compiled with MinGW-GCC 3.4.2. See here. Please note that the original project was developed with Trolltech Educational Qt 3.3.3 version).

What I have done:

  • Create a C::B project (GUI). Do not forget to add include/lib directories and to add the necessary libraries to the linker. If you use the Qt dll, then add this to the project directory (where the .exe will be generated).
  • Define Qt global variable (I have called mine simply "Qt").
  • Add custom builds (under file properties) to CDIToolDefault.ui. First 2 commands with uic.exe tool to generate CDIToolDefault.h and CDIToolDefault.cpp. Then a command with the moc.exe tool to moc the CDIToolDefault.h and generate the moc_CDIToolDefault.cpp.

Quote
$(#Qt)\bin\uic.exe ".\CDIToolDefault.ui" -o ".\CDIToolDefault.h"
$(#Qt)\bin\uic.exe ".\CDIToolDefault.ui" -i ".\CDIToolDefault.h" -o ".\CDIToolDefault.cpp"
$(#Qt)\bin\moc.exe ".\CDIToolDefault.h" -o ".\moc_CDIToolDefault.cpp"

One command per line.
Do not forget to check the box "Use custom command to build this file" in the Advanced tab and the box "Compile file" in the General tab :).

  • Re-build.
  • Add the 3 new files to the project.
  • As the CDITool.h contains a Q_OBJECT macro, it is necessary to custom build (under file properties) this file by using the moc.exe and generate the moc_CDITool.cpp.

Quote
$(#Qt)\bin\moc.exe CDITool.h -o .\moc_CDITool.cpp

Do not forget to check the box "Use custom command to build this file" in the Advanced tab and the box "Compile file" in the General tab :).

  • Re-build.
  • Add moc_CDITool.cpp to the project.
  • Re-build.

I got a lot of warnings :(. Probably because I am using GCC 4.1.0 :).

If you have questions/comments/critics, you can post them here.

Best wishes,
Michael

PS.: If you want to create a Qt application from scratch, you can just create a main.cpp file and one or more .ui files (using the Qt Designer). Then by using the uic.exe and moc.exe tool you create the .h, .cpp and moc files and add them to your project. Anyway, for more info you can visit the Trolltech website.

A last remark: I did not use Qt project file, i.e., .pro file. I have never used them and probably I will continue not to use them :).
« Last Edit: March 31, 2006, 09:16:02 pm by Michael »

Boris

  • Guest
Re: Using C::B to build Qt applications
« Reply #1 on: June 05, 2006, 12:07:48 pm »
Qt 4.1.3
Code
  $(#Qt)\bin\uic.exe ".\CDIToolDefault.ui" -i ".\CDIToolDefault.h" -o ".\CDIToolDefault.cpp"

Not work????

Offline Michael

  • Lives here!
  • ****
  • Posts: 1608
Re: Using C::B to build Qt applications
« Reply #2 on: June 05, 2006, 05:51:42 pm »
Qt 4.1.3
Code
  $(#Qt)\bin\uic.exe ".\CDIToolDefault.ui" -i ".\CDIToolDefault.h" -o ".\CDIToolDefault.cpp"

Not work????

Hello,

What exactly does not work? It works fine for me (both with C::B and M$ VS C++ .NET 2003).

Best wishes,
Michael

Boris

  • Guest
Re: Using C::B to build Qt applications
« Reply #3 on: June 06, 2006, 06:37:59 am »
Sorry for my english,
Code
Qt user interface compiler 4.1.3.
Usage: D:\Qt\4.1.3\bin\uic.exe [OPTION]... <UIFILE>

  -h, -help                 display this help and exit
  -v, -version              display version
  -d, -dependencies         display the dependencies
  -o <file>                 place the output into <file>
  -tr <func>                use func() for i18n
  -p, -no-protection        disable header protection
I can't see "-i". Key "-i" not work.

lfm

  • Guest
Re: Using C::B to build Qt applications
« Reply #4 on: June 06, 2006, 10:19:14 am »
Please use QT4, because QT4 had changed very much  from QT3

Offline yop

  • Regular
  • ***
  • Posts: 387
Re: Using C::B to build Qt applications
« Reply #5 on: June 06, 2006, 08:02:08 pm »
Qt 4.x uic does not output implementation files anymore (.cpp files) and the -i switch has become obsolete. In Qt 3 it works fine. The rest of the steps that Michael proposes should work fine though.
Life would be so much easier if we could just look at the source code.

Offline Michael

  • Lives here!
  • ****
  • Posts: 1608
Re: Using C::B to build Qt applications
« Reply #6 on: June 20, 2006, 08:20:30 pm »
Qt 4.x uic does not output implementation files anymore (.cpp files) and the -i switch has become obsolete. In Qt 3 it works fine.

Hello,

I did not know :oops:. Thank you for pointing that out :).

Best wishes,
Michael