Chapter 1. Getting started

The following program listing is a simple KDE program (without any hk_classes parts). It just opens a main widget.

#define HAVE_SSTREAM 1
#include <kapp.h>
#include <kaboutdata.h>
#include <kcmdlineargs.h>
#include <klocale.h>
#include <qwidget.h>

static const char *description =
    I18N_NOOP("A hk_kdeclasses example Application");

static const char *version = "v0.1";


int main(int argc, char **argv)
{
    KAboutData about("hk_kdeexample", I18N_NOOP("hk_kdeexample"), version, description, KAboutData::License_GPL, "(C) 2001 Horst Knorr", 0, 0, "hk_classes@knoda.org");
    about.addAuthor( "Horst Knorr", 0, "hk_classes@knoda.org" );
    KCmdLineArgs::init(argc, argv, &about);

    KApplication app;

    QWidget* widget = new QWidget;

    app.setMainWidget(widget);
    widget->show();

    int res = app.exec();
}   return res;

And in the following program listing you see the example of chapter 2 of the hk_classes tutorial


#define HAVE_SSTREAM 1
  #include <hk_classes.h>
  #include <iostream>
  int main()
  {
  hk_drivermanager* mydrivermanager = new hk_drivermanager(false);
  if (mydrivermanager==NULL) {cout <<"error creating mydrivermanager"<<endl;exit(1);}
  hk_connection* myconnection = mydrivermanager->new_connection();
  if (myconnection==NULL) {cout <<"error creating myconnection"<<endl;exit(1);}
  myconnection->connect();

  hk_database* mydatabase=myconnection->new_database("exampledb");
  if (mydatabase==NULL) {cout <<"error creating mydatabase"<<endl;exit(1);}
  hk_datasource* mydatasource= mydatabase->new_table("authors");
  if (mydatasource==NULL) {cout <<"error creating mydatasource"<<endl;exit(1);}
  mydatasource->enable();
  //the following internal debugging command should not be used. It is used here for
  //demonstration purposes only!!!!
  mydatasource->dump_data(); // DON'T USE THIS COMMAND IN YOUR PROGRAMS!!!

  delete mydrivermanager;
  }

Now we merge these 2 programs.

Example 1.1. The first program

#define HAVE_SSTREAM 1
#include <kapp.h>
#include <kaboutdata.h>
#include <kcmdlineargs.h>
#include <klocale.h>
#include <qwidget.h>
#include <hk_classes.h>
#include <iostream>

static const char *description =
    I18N_NOOP("A hk_kdeclasses example Application");

static const char *version = "v0.1";


int main(int argc, char **argv)
{
    KAboutData about("hk_kdeexample", I18N_NOOP("hk_kdeexample"), version, description, KAboutData::License_GPL, "(C) 2001 Horst Knorr", 0, 0, "hk_classes@knoda.org");
    about.addAuthor( "Horst Knorr", 0, "hk_classes@knoda.org" );
    KCmdLineArgs::init(argc, argv, &about);
    KApplication app;
    QWidget* widget = new QWidget;
    app.setMainWidget(widget);

    hk_drivermanager* mydrivermanager = new hk_drivermanager(false);
    if (mydrivermanager==NULL) {cout <<"error creating mydrivermanager"<<endl;exit(1);}
    hk_connection* myconnection = mydrivermanager->new_connection();
    if (myconnection==NULL) {cout <<"error creating myconnection"<<endl;exit(1);}
    myconnection->connect();

    hk_database* mydatabase=myconnection->new_database("exampledb");
    if (mydatabase==NULL) {cout <<"error creating mydatabase"<<endl;exit(1);}
    hk_datasource* mydatasource= mydatabase->new_table("authors");
    if (mydatasource==NULL) {cout <<"error creating mydatasource"<<endl;exit(1);}
    mydatasource->enable();

    widget->show();

    int res= app.exec();
    delete mydrivermanager;
    return res;
}

Compile this program and start it. It works as the 2 programs were planned to do. The hk_classes part of the application asks for login information on the console and then the widget starts. This is very unsatisfactory. When we use KDE we also want to use its functionalities.