KHelloWorld @ KDE - Linux Life

はじめに

KDEでつくるHelloWorldです。

khelloworld.h

 1#ifndef KHELLOWORLD_H
 2#define KHELLOWORLD_H
 3
 4#include <kmainwindow.h>
 5
 6class KHelloWorld : public KMainWindow
 7{
 8    Q_OBJECT
 9public:
10    KHelloWorld();
11    ~KHelloWorld();
12};
13
14#endif /* KHELLOWORLD_H */

khelloworld.cpp

 1#include "khelloworld.h"
 2
 3#include <qpushbutton.h>
 4
 5KHelloWorld::KHelloWorld()
 6{
 7    QPushButton* button = new QPushButton( "Hello World!", this );
 8    connect( button, SIGNAL( clicked() ), this, SLOT( close() ) );
 9    setCentralWidget( button );
10    resize( 100, 40 );
11}
12
13KHelloWorld::~KHelloWorld()
14{
15}

main.cpp

 1#include <kapplication.h>
 2#include <kaboutdata.h>
 3#include <klocale.h>
 4#include <kcmdlineargs.h>
 5#include "khelloworld.h"
 6
 7static const char description[] = I18N_NOOP( "Hello World from KDE." );
 8
 9static const char version[] = "1.0";
10
11int main( int argc, char* argv[] )
12{
13    KAboutData aboutData( "KHelloWorld", I18N_NOOP( "KHelloWorld") , version, description, KAboutData::License_GPL, "(c)2003, Tasuku Suzuki" );
14    aboutData.addAuthor( "Tasuku Suzuki", 0, "tasuku@linux-life.net" );
15
16    KCmdLineArgs::init( argc, argv, &aboutData );
17
18    KApplication app;
19    if( app.isRestored() )
20    {
21        RESTORE( KHelloWorld )
22    }
23    else
24    {
25        KHelloWorld* khelloworld = new KHelloWorld();
26        khelloworld->show();
27    }
28    app.exec();
29}

コンパイル

まず、khelloworld.h から moc ファイルを作成します。

$ moc -o khelloworld.moc.cpp khelloworld.h

ソースファイルをコンパイルします。

$ gcc -c *.cpp -I$KDEDIR/include -I$QTDIR/include

最後にオブジェクトファイルをリンクします。

$ gcc -o khelloworld *.o -L$KDEDIR/lib -L$QTDIR/lib -lqt -lkdecore -lkdeui

実行

$ ./khelloworld

スポンサードリンク

Copyright - ©2003- tasuku All Rights Reserved