
In this step I describe how a window class is created.
Now there are three files
/************* khello.h *******************/
#include <kapp.h>
#include <kmainwindow.h>
class KHello : public KMainWindow
{
Q_OBJECT
public:
void closeEvent(QCloseEvent *);
};
/************* khello.cc ******************/
#include "khello.moc"
void KHello::closeEvent(QCloseEvent *e)
{
kapp->beep();
KMainWindow::closeEvent(e);
}
/************* main.cc ********************/
#include "khello.h"
int main( int argc, char **argv )
{
KApplication a( argc, argv, "khello" );
KHello *w = new KHello();
w->setGeometry(100,100,200,100);
a.setMainWidget( w );
w->show();
return a.exec();
}
|
There are a few commands that need explaining:
| Q_OBJECT |
| void closeEvent(QCloseEvent *); |
| #include "khello.moc" |
The meta object compiler produces a moc file, which you must include. The moc file is an extended version of your header file.
g++ -c -I$KDEDIR/include -I$QTDIR/include -fno-rtti main.cc moc khello.h -o khello.moc g++ -c -I$KDEDIR/include -I$QTDIR/include -fno-rtti khello.cc g++ -L$KDEDIR/lib -L$QTDIR/lib -lkdeui -lkdecore -lqt -ldl -o khello main.o khello.o
[if moc is not in your path try $QTDIR/bin/moc]
[updated by] David Leimbach
2003-02-26
[original author] Daniel Marjamäki
2000-02-01