Development/Tutorials/KDE2/KHello/Tutorial 1

< Development‎ | Tutorials‎ | KDE2‎ | KHello
Revision as of 20:52, 29 June 2011 by Neverendingo (Talk | contribs) (Text replace - "</code>" to "</syntaxhighlight>")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


This is, as far as I know, the simplest possible KDE program.

Source code

The source code is very simple:

 1 /************* *******************/
 2 #include <kapp.h>
 3 #include <kmainwindow.h>
 5 int main( int argc, char **argv )
 6 {
 7   KApplication a( argc, argv, "khello" );
 8   KMainWindow *w = new KMainWindow();
 9   w->setGeometry(100,100,200,100);
11   a.setMainWidget( w );
12   w->show();
13   return a.exec();
14 }
15 /************* end of file *****************/

Explaining the code

Here is the commands explained:

#include <kapp.h>
#include <kmainwindow.h>

The kapp.h file contain some basic code needed by all programs, and the kmainwindow.h file contains the class which should be used for all main windows in KDE programs.

KApplication a(argc, argv);
KMainWindow *w = new KMainWindow();

Create a KApplication object and a KMainWindow object. The KApplication object will contain all the basic code our program needs, and the KMainWindow object will be our main window.


Move and resize the window. It is moved to coordinates (100, 100), and the size is changed to 200x100 (width x height).

a.setMainWidget( w );

Our program needs to know where to find the main window.


Make the main window visible.

return a.exec();

Execute the program.


[on linux where KDEDIR and QTDIR contain the paths to where KDE and Qt are installed respectively]

[FreeBSD 5.x users may omit the -ldl]

g++ -c -I$KDEDIR/include -I$QTDIR/include -fno-rtti
g++ -L$KDEDIR/lib -L$QTDIR/lib -lkdeui -lkdecore -lqt -ldl -o khello khello.o

This page was last modified on 29 June 2011, at 20:52. Content is available under Creative Commons License SA 4.0 unless otherwise noted.