qtgtk  
   
 

Introduction

Historically a choice between KDE and GNOME frameworks has been a permanent one for application developers. People were lead to believe that using functionality of one toolkit while using the event loop of the other is impossible. So even though many GNOME developers would love to integrate their applications more closely with KDE by using our native dialogs it was simply impossible. Up till now...

Integration

We wanted make the life of the developers who think about integrating with KDE more closely a lot easier. The basic goals of the whole undertaking were:
  • make is incredibly simple to integrate Qt event loop into a GTK+ application for the application authors
  • make it possible for developers to start incrementally switching GTK+/GNOME applications to Qt/KDE without loosing any functionality

We achieved those goals with a trivial implementation of a GSource which integrates Qt event loop into Glib event loop.

So how to use it in your projects?

QtGTK is currently a very small library - you can either include the necessary files along your application or you may choose to simply link to libqtgtk, which is also the preferred method.

If you choose to link to libqtgtk you need to change your configure.in file a little bit. First we suggest that you add

AC_ARG_ENABLE(kde, [  --enable-kde   enable KDE-friendliness ], 
              enable_kde=$enableval, enable_kde=auto ) 

which will let users specify ./configure --enable-kde option while configuring your application/library. Secondly you should add the actual checks for libqtgtk to make sure the library is there and ready to be linked to. You do that by adding the following checks to your configure.in file :

# QtGTK detection
PKG_CHECK_MODULES(YOURAPP_KDE, qtgtk, have_kde=yes, have_kde=no)

if test x$have_kde = xno ; then
    AC_MSG_WARN([QtGTK development library not found])
fi

if test x$enable_kde = xyes; then
    if test x$have_kde = xno; then
	AC_MSG_ERROR([KDE explicitly required, and QtGTK development library not found])
    fi
fi

if test x$enable_kde = xno; then
   have_kde=no;
fi

AM_CONDITIONAL(HAVE_KDE, test x$have_KDE = xyes)

dnl KDE flags
AC_SUBST(YOURAPP_KDE_CFLAGS)
AC_SUBST(YOURAPP_KDE_LIBS)
Now you're all set. To use any KDE dialog natively in your application all you have to do is add the following code:
#include <config.h>
#ifdef HAVE_KDE
#include <qtgtk/qtgtk.h>
#endif
And do the actual integration with one function call:

qtgtk_init( 0 );

Calling this method integrates Qt event loop in your application and from now on you can be using all Qt and KDE dialogs just like they would be native.

The additional argument to that function is the GMainContext with which you want to integrate. If you don't know what GMainContext is - don't worry about it, just pass NULL to that function and it will deduce the context for you.

Finally make sure to look at the example : buttons.cpp

Dialogs for GNOME developers

Once you have called the qtgtk_init function in your application you can use all Qt/KDE dialogs in your application. Here's a list of dialogs which you may consider using:
HeaderDescription
kinputdialog.h This file contains standard KDE input dialogs which you can use to get text, numbers or a selection from the user.
kmessagebox.h File contains all standard KDE message boxes. Note that all dialogs in this file allow you to pass a window id as the parent which will assure in your GTK+ applications that the boxes aren't hidden accidently by the user.
kfiledialog.h Provides a user (and developer) friendly way to select files and directories.
kicondialog.h Dialog for interactive selection of icons. Use the function getIcon() let the user select an icon.
kdirselectdialog.h Contains a pretty dialog for a for selecting directories.
 
   
 
 
  kde