KHello #1 - The Simplest Possible KDE Program




Description

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

Source code

The source code is very simple:
/************* khello.cc *******************/
#include <kapp.h>
#include <ktmainwindow.h>

int main( int argc, char **argv )
{
  KApplication a( argc, argv );
  KTMainWindow *w = new KTMainWindow();
  w->setGeometry(100,100,200,100);

  a.setMainWidget( w );
  w->show();
  return a.exec();
}
/************* end of file *****************/

Explaining the code

Here is the commands explained:

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

KApplication a(argc, argv);
KTMainWindow *w = new KTMainWindow();
Create a KApplication object and a KTMainWindow object. The KApplication object will contain all the basic code our program needs, and the KTMainWindow object will be our main window.

w->setGeometry(100,100,200,100);
Move and resize the window. It is moved to coordinates (100, 100), and the size are changed to 200x100 (width x height).

a.setMainWidget( w );
Our program needs to know where to find the main window.

w->show();
Make the main window visible.

return a.exec();
Execute the program.

Compiling

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

[Next >>]


Daniel Marjamäki
2000-02-01