Building Qt Applications using your favorite text editor

I have used C++ for about 5 years now, and it is really a very powerful programming language. But I found one big disadvantage; it is too hard to make a C++ GUI. I used to do that by Windows API, but it is difficult to learn and I can’t learn my students all Windows API concepts for just making some forms and buttons!

Recently I heard about Qt and decided to learn it. As usual I stuck at the beginning; how could I build a Qt Application? and as usual too I do it my way 😉

Building Qt Applications using Notepad

If your favorite text editor is still Notepad!, you must build your Qt Applications using command line.

To let it easy to you, I made a batch file depends on what compiler you want to use to build Qt Applications.

Building Qt Opensource Version using MingW

If you are using Qt Opensource Version you can use this batch file to build and run Qt Applications:

::::::::::::::::::::::: This is Qt building batch by Madhat Alsoos :::::::::::::::::::::::
:: First argument is the directory of the project
:: Second argument is the name of the cpp file without .cpp

@echo off
cd %1
set QTDIR=%1
set PATH=C:\Qt\2009.04\qt\bin;C:\Qt\2009.04\bin;C:\Qt\2009.04\mingw\bin;C:\WINDOWS\System32;%PATH%
set QMAKESPEC=win32-g++
qmake -project
qmake
mingw32-make.exe
IF not ERRORLEVEL 1 start debug\%2.exe

You can use this batch by passing the directory of the .cpp file and its name like this:

build.bat c:\qt\test\helloworld helloworld

It is so easy! First set Qt base directory to directory of file which we want to build (which will be passed as an argument to this batch file), then add Qt installation directory to the PATH system variable (just in case) and set QMAKESPEC to win32-g++ which tells Qt that it should make the project for g++ compiler. After that we make the .pro file (Qt project file) and compile it using mingw32 (which came by default with your Qt open source verison).

Note that you must change Qt path in this batch to where you installed Qt, or simply add your Qt bin folders to PATH system variable.

Building Qt Commercial Version using Visual Studio

If you are using Qt Commercial Version you can use this batch file to build and run Qt Applications:

Read the rest of this entry »