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:

::::::::::::::::::::::: 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\4.4.3\bin;C:\Program Files\Microsoft Visual Studio 9.0\VC\bin;%PATH%
set QMAKESPEC=win32-msvc2008
call "C:\Program Files\Microsoft Visual Studio 9.0\Common7\Tools\vsvars32.bat"
qmake -project
qmake
nmake
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

As you see, I used nmake to build and link the Qt Application which means that you must have Visual Studio installed on your computer to use this batch file. If your using Commercial Version and you don’t have Visual Studio on your computer you can install MingW and use the first batch file which should work in this case too.

Note that you must change Qt path and Visual Studio path in this batch to where you installed them, or simply add you Qt bin folder and Visual Studio bin folder to PATH system variable.

Building Qt Applications using EmEditor

If your favorite text editor is EmEditor, you can make a small button at EmEditor Tools Toolbar and call any of the above batches in it.

Just open EmEditor and go to Tools > External Tools > Customize Tools and click New button, and fill in fields like this:

EmEditor Build Qt Button

Then you will find a small button in EmEditor Tools Toolbar which will do all things for you:

EmEditor Qt

Building Qt Applications using Notepad++

If your favorite text editor is Notepad++ then you are my man, so I made a Notepad++ plugin named QtNpp just for you πŸ˜‰

You can download it (and even change the way it build your Qt Applications) from my post β€œQtNpp: Notepad++ Plugin to build Qt Applications”.

 Notepad++ Qt

Advertisements

5 Responses to “Building Qt Applications using your favorite text editor”

  1. Arul Says:

    Help me about qmake?
    I have created using Qt Designer
    hello.pro
    hello.h
    hello.cpp
    main.cpp
    hello.ui
    Now i want compile and run the program. I am new to this program help me?

    • Madhat Alsoos Says:

      Just open command and change current folder to your project folder and type:
      qmake -project
      qmake

      then type: mingw32-make.exe if you have MingW
      or type: nmake if you have Visual Studio

      you should see your executable file now

      Or you can simply use Qt Creator which is a free IDE to create,build and run Qt project
      you can download Qt Creator from here:
      http://qt.nokia.com/downloads/downloads#lgpl

  2. Arul Says:

    Thank you for your reply, I want to run in redhat linux os?

  3. Dimitri Says:

    Thanks, Madhat!
    I was searching to find a way to automate the build process for our project, which include Qt and Visual studio sub projects and your article really helped me.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: