In the former post I wrote how I setup the QT environment. Now I start the project. Although it will be a GUI application, first I will just make a simple Hello World proggee to get familiar with the project creation and basic tools. It will not even be a real QT application since I will not use any QT libraries. It will be pure C++ but I will use QT build tools.
Lets make a folder to our project: fractal
When I work alone on a project I do not like to mess with version control tools. I just prefer to make copies of my project folder. I use a running number in the folder name.
So I will make a new folder under the fractal folder called fractal001.
I like to keep the sources and headers separated, so I create an include and an src folder under fractal001.
Now my directory structure looks like this:
The next step is to write a small C++ program that prints to the console: Hello World! Open a text editor and write one!
Here is the code:
#include <iostream.h>
main()
{
cout << “Hello World!”;
return 0;
}
I save it as main.cpp to the src folder.
Now we should compile this somehow. QT has a very nice tool called qmake. It can be used to create a QT specific project file, which can be used to generate traditional Make files. I found it easier than to write the Makefile myself. So lets go to the fractal001 folder and type:
qmake -project
It will create a file called fractal001.pro Here is the content:
#########################################################
# Automatically generated by qmake (2.01a) Tue Nov 18 08:58:42 2008
#########################################################
TEMPLATE = app
TARGET =
DEPENDPATH += . src
INCLUDEPATH += .
# Input
SOURCES += src/main.cpp
Lets rename the file to fractal.pro and lets make some changes!
We can use the TARGET variable to give a name to the compiled executable. Lets call it Arthur eheh.
TARGET = arthur
Probably you already recognized that qmake didn’t add our include folder to the INCLUDEPATH. It is because it is still empty. Lets add it:
INCLUDEPATH += . include
Please note the space after the dot. INCLUDEPATH is a space separated list. Dot means the current folder.
Save the file. Open a console and go to the fractal/fractal001 folder. Type qmake
It will generate the Makefile for you. Then just type make
If you did everything fine, make will compile the sources to an executable called arthur
type ./arthur and smile
You can get the sources from here: fractal001
