User forums > Using Code::Blocks

Using C::B to build Qt applications

(1/2) > >>

Michael:
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"

--- End quote ---

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

--- End quote ---

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 :).

Boris:
Qt 4.1.3

--- Code: ---  $(#Qt)\bin\uic.exe ".\CDIToolDefault.ui" -i ".\CDIToolDefault.h" -o ".\CDIToolDefault.cpp"

--- End code ---

Not work????

Michael:

--- Quote from: Boris 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"

--- End code ---

Not work????

--- End quote ---

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

--- End code ---
I can't see "-i". Key "-i" not work.

lfm:
Please use QT4, because QT4 had changed very much  from QT3

Navigation

[0] Message Index

[#] Next page

Go to full version