Chapter 3. Creating the application

Starting the project

Creating the framework with KDevelop

The framework in which our program will sit in (i.e. the main window) can be done easily and quickly by using KDevelop. Start KDevelop and select New Project in the Project menu. The Application Wizard appears then. Choose a C++ -> KDE -> Simple KDE Application. Fill in the blank lines with the project name (SigCreate), your name as author, your email (see Picture 1).


Application Wizard
Click on Next, have a look to the CVS option and to the header templates. Then click on Finish on the last screen. KDevelop creates all the files that you need to compile your project. You can use the file selector to view the code of the 3 files which are main.cpp, sigcreate.cpp and sigcreate.h (picture 2).

KDevelop file view
Once the Application Wizard has created your application, compile it to ensure that everything is fine. To do that, select Build -> Run automake & friends then Build -> Run configure. The Messages output window should say
" Good - your configure finished. Start make now
*
* *** Success ***
so you can run "make" with Build -> Build Project (or using the F8 shortcut). Then Build -> Install. Then Build -> Execute program (or F9). The result is shown in Picture 3.

The KDE Simple Application
Picture 3: The KDE Simple Application

We now have our framework and are ready to start developing our program.

If KDevelop does not recognize your QTDIR and KDEDIR variables, you can set them in Project -> Project Options... in Configure Options.


Project Options
Picture 6: Project Options

Using Qt Designer

Qt Designer is a tool for designing and implementing user interfaces. It helps you arranging your widgets on a form and adding a proper layout so your interface can be resized properly. I recommand that you read the Qt Designer manual to know everything about Qt Designer. Qt Designer includes a code editor but we'll use KDevelop to edit and modify all code.

We will now create the interface of our application using Qt Designer. A form from Qt Designer is saved with a .ui extension because it is then processed by the uic program to generate a .h and .cpp files. KDevelop takes care of that, the only thing we need to do is to create the form.

Note

Each time you add or remove a file (now we will add a .ui file) in your KDevelop project, the Makefile.am will be changed. KDevelop does that itself but you will need to Run automake & friends after such changes.

In KDevelop, click on File -> New and fill the dialog window that appears. First write the file name: sigcreatedlg and select what new file you want in the combobox: here we want a Widget (.ui). Please be sure that "Add to project" is checked, this ensures that the Makefile.am is updated.


Adding a .ui file
Click the Ok button. The Automake manager dialog then pops up.

Automake manager
Click the OK button.

If the new file sigcreatedlg.ui is not open in Qt Designer, open the Automake Manager, right-click on the file and select Open With then you should have designer. Choose it. Qt Designer will open.

Note

About the names: it is a good idea to finish a dialog name or a form name by dlg to ensure a nice lisibility for people who want to have a look at the code. sigcreatedlg says that it is a dlg i.e an interface class only. Usually, KDE class names begin with K (upper case) followed by the name that describes the more closely your program. I should have choosen KSigCreate if it was a real KDE app.

Qt Designer
Qt Designer interface is essentially split into three areas. On the left is the toolbox, i.e you can select your widgets here. On the right, several dialogs can be selected, I'll keep only the Property Editor dialog (I close the 2 others). Your widgets can be fine tuned to behave how you want them to. You can choose there the size of the widget, its background color (palette) and so on. Between those 2 windows is the Form which is your program window, within which you will design your user interface.

Note

After adding the sigcreatedlg.ui file, you will have to run Automake & friends and to Run configure before building the program, this ensures that the Makefile.am which has been updated is now read.