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.
$(#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.
$(#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
.