Monday, July 7, 2008

Writing, compiling and executing a Qt program on Windows XP

Hi all,

To compile a qt program first make a folder and make a cpp file in this folder and add the appropriate code. For your reference I created a C:\Qt\First and then added a main.cpp with the following contents:
#include
#include

int main(int argc, char* argv[])
{
QApplication app(argc,argv);
QPushButton button;
button.setText("FIRST BUTTON");
button.show();
return app.exec();
}

Then execute the following standard commands one by one:
qmake -projects
qmake
make
This will create 3 make files namely Makefile, Makefile.Debug, Makefile.Release.
To create an executable: type the command: make -f Makefile.Release
This creates a release folder. The executable is in this release folder. Change to this folder and execute the exe.
Remember that every time you change your code, compile your program with the above command to recreate the release which reflects the changes that you have made.
That's it you are on your way to bigger things in Qt

HAPPY PROGRAMMING
For any queries leave your comments and I will get back to you soon.

Cheers!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

MANDELBROT

INSTALLING QT ON WINDOWS XP

Hi all,

This is the trickiest installation I have done. The trick is to have the right information and it is that on a Windows machine only the commercial release is compatible with Microsoft Visual Studio so if you are stuck with strange errors creeping up when you try to install open source edition with msvc option you know where is the problem. Thus, for Qt open source edition install a mingw compiler on your system. The mingw homepage (mingw.org) sucks, the download links have nothing to download, it is the worst website of all open source projects. The work around for this is to download Bloodshed Dev C++. This will install everything that you need to start your installation for Qt. Do remember that if you have microsoft visual studio installed clear the environment variables MSYS, LIB and INCLUDE (NOTE:-To check all the environment variables that are set on your machine, type the following command: set on a windows console.). This is done using "set" command from the console as follows
  1. set LIB=
  2. set INCLUDE=

This clears any entries for visual studio from LIB and INCLUDE. Now comes the steps that you need to take to install qt. I am using Qt-4.3.3 open source edition.
  1. Unzip the Qt folder to C: drive so you have a qt source folder in C:\
  2. I have Bloodshed Dev C++ installed in C:\Dev-Cpp. Add the bin and library sub folder of this folder to your PATH variable using PATH=%PATH%;C:\Dev-Cpp\bin;C:\Dev-Cpp\lib. This would relieve you all the hassles of finding and installing a mingw compiler as Bloodshed Dev C++ automatically installs them for you. Also change your LIB and INCLUDE environment variables (after clearing the visual studio entries) to point to Dev-Cpp and Qt lib and include folder. I made the following changes on the console: set LIB=%LIB%C:\Dev-Cpp\lib;C:\qt-win-opensource-src-4.3.4\lib( I unzipped Qt folder to C:\ drive, if you choose some other path then change it accordingly). set INCLUDE=%INCLUDE%:C:\Dev-Cpp\include;C:\qt-win-opensource-src-4.3.4\include.
  3. Then switch to the qt folder i.e where you have unzipped the qt source folder. In my case it is C:\qt-win-opensource-src-4.3.4. From there type the command: configure -platform win32-g++ to configure Qt for your system. The command will only fail if you haven't set the path for the mingw based compiler correctly other wise in a matter of 5-10 minutes your version of qt will be ready to be built.
  4. When qt is configured run the following command to build qt for your system: mingw32-make. If you face any errors during this step it is most likely that you have visual studio installed and environment variables like LIB, INCLUDE AND MSYS set to point to exe's needed by visual studio. Clearing these variables and setting them as I have explained above will relieve you of your hassles.
  5. Finally add Qt bin directory's path to your PATH variable as PATH=%PATH%;C:\qt-win-opensource-src-4.3.4\bin (in my case).

I hope this does the trick for all of you geeks who were hitting a dead end while installing Qt on your windows machines. For any further queries you can send a comment and I will try to answer them to the best of my abilities.

Cheers!!!!!!!!!!!!!!!!!!!!!!!!!!!!