Chapter 2. A Simple KDE Application

by David Sweet

In This Chapter

The goal of the KDE project is to create a set of desktop applications that share a common user interface. To this end, the KDE developers have created a set of C++ classes that help you get the KDE look and feel with minimal effort. You create a KDE-style application by deriving the KDE class KTMainWindow and using the event loop (discussed in Chapter 3, "The Qt Toolkit") in the class KApplication. These classes will handle look-and-feel issues that are common to most KDE applications, leaving you free to focus on programming the tasks unique to your application.

2.1. The Linux/UNIX Programmer's Desktop

Now is a good time to collect the tools you will need for developing KDE software. At the very least, you need an editor to edit your source code and a way to access the C++ compiler. Optionally, you may also want to use a debugger to make the debugging of your code more efficient.

2.1.1. Necessities for Editing Code

Several editors are available for Linux/UNIX systems. Two popular ones are vi and emacs. If you are familiar with UNIX, you will be familiar with these programs. For those of you who are new to UNIX: vi is a simple text editor with a unique, sometimes difficult, interface. It would not be familiar if you are used to a Macintosh- or Windows-based source-code editor. emacs is somewhat more familiar and has a very powerful LISP-based macro language.

If you want a more modern-feeling editor, you could try kfte or kwrite. kfte is a full-fledged source-code editor. kwrite is a simpler, general text editor, but it does provide a key-mapping more familiar to Macintosh/Windows users and syntax highlighting for C++ (as well as for other file types).

The KDE taskbar is very helpful in a bare-bones programming environment such as I am describing here. If you are editing several source-code files at once (and in separate windows) the title of each window is listed in the taskbar. Clicking that taskbar button opens and/or raises that window and gives it the focus.

To make the taskbar a little more useful, you should set the title of your window to be the name of the file you are editing. If you are using emacs, for example, you can type emacs filename -T title to set the title of the emacs window (see Figure 2.1). kwrite and kfte set their window titles automatically.

Figure 2.1. It is helpful to have an editor display the filename first in the caption.

2.1.2. Debuggers Available for Linux

The debugger that is probably already installed on your system is called gdb, the GNU debugger. It is a command-line based utility that allows you to set breakpoints, step through programs, and view the contents of program variables.

GUI debuggers are also available. kdbg is a KDE front end to gdb. It gives a friendly, intuitive interface to gdb, which makes learning the tool much easier. It is available from Another GUI debugger, although not KDE-based, is DDD. It is known for its capability to display program data in graphical format, including trees and plots of array data. It is available from