Development/Tutorials/First program: Difference between revisions

From KDE TechBase
(syntax highlighting)
No edit summary
Line 1: Line 1:
Your first program shall greet the world with a friendly "hello world", what else ? For that, we will use a KMessageBox. To get more information about the KMessageBox-Class, type "kde: kmessagebox" in your konqueror and it will redirect you to http://developer.kde.org/documentation/library/cvs-api/kdelibs-apidocs/kdeui/html/classKMessageBox.html
Your first program shall greet the world with a friendly "hello world", what else ? For that, we will use a KMessageBox. To get more information about the KMessageBox-Class, type "kde: kmessagebox" in your konqueror and it will redirect you to http://developer.kde.org/documentation/library/cvs-api/kdelibs-apidocs/kdeui/html/classKMessageBox.html
<code cppqt n>
<code cppqt n>
#include <QString>
#include <QString>
#include <kapplication.h>
#include <kapplication.h>
#include <kaboutdata.h>
#include <kaboutdata.h>
#include <kmessagebox.h>
#include <kmessagebox.h>
#include <kcmdlineargs.h>  
#include <kcmdlineargs.h>  
 
int main (int argc, char *argv[])
int main (int argc, char *argv[])
{
{
  KAboutData aboutData( "test", "test",
KAboutData aboutData( "test", "test",
                        "1.0", "test", KAboutData::License_GPL,
                      "1.0", "test", KAboutData::License_GPL,
                        "(c) 2006" );
                      "(c) 2006" );
  KCmdLineArgs::init( argc, argv, &aboutData );
KCmdLineArgs::init( argc, argv, &aboutData );
  KApplication khello;
KApplication khello;
  KGuiItem kgi( QString( "Hello" ), QString(),
KGuiItem kgi( QString( "Hello" ), QString(),
                QString( "this is a tooltip" ),
              QString( "this is a tooltip" ),
                QString( "this is whatsthis" ) );
              QString( "this is whatsthis" ) );
  KMessageBox::questionYesNo( 0, "text", "caption", kgi );
KMessageBox::questionYesNo( 0, "text", "caption", kgi );
}
}
</code>
</code>
If you set up your environment as described in [[Build/Unstable Version|Build/Unstable Version]], you can compile this code with
If you set up your environment as described in [[Build/Unstable Version|Build/Unstable Version]], you can compile this code with

Revision as of 21:26, 17 December 2006

Your first program shall greet the world with a friendly "hello world", what else ? For that, we will use a KMessageBox. To get more information about the KMessageBox-Class, type "kde: kmessagebox" in your konqueror and it will redirect you to http://developer.kde.org/documentation/library/cvs-api/kdelibs-apidocs/kdeui/html/classKMessageBox.html

  1. include <QString>
  2. include <kapplication.h>
  3. include <kaboutdata.h>
  4. include <kmessagebox.h>
  5. include <kcmdlineargs.h>

int main (int argc, char *argv[]) {

KAboutData aboutData( "test", "test",
                      "1.0", "test", KAboutData::License_GPL,
                      "(c) 2006" );
KCmdLineArgs::init( argc, argv, &aboutData );
KApplication khello;
KGuiItem kgi( QString( "Hello" ), QString(),
              QString( "this is a tooltip" ),
              QString( "this is whatsthis" ) );
KMessageBox::questionYesNo( 0, "text", "caption", kgi );

} If you set up your environment as described in Build/Unstable Version, you can compile this code with

gcc hello.cpp -o hello -I/home/kde-devel/qt-unstable/include/Qt \
-I/home/kde-devel/qt-unstable/include/Qt-Core \
-I/home/kde-devel/qt-unstable/include -I/home/kde-devel/kde/include \
-L/home/kde-devel/kde/lib \
-L/home/kde-devel/qt-unstable/lib -lkdeui -lkdecore -ldl 

and then run it with ./hello

Tip
Note: This page is about KDE 4. It isn't applicable for KDE 3 development.