Development/Tutorials/KDE4 Porting Guide

< Development‎ | Tutorials
Revision as of 18:07, 24 February 2007 by Dhaumann (Talk | contribs)

Jump to: navigation, search



A tutorial intended to help developers port their Qt3/KDE3 based applications to Qt4/KDE4. Porting a KDE3 based application needn't be a difficult process. Already, there are many scripts and sources of documentation which can help.


For the instructions in this tutorial we use the following shorthand:

  • program refers to an executable program
  • path refers to a path
  • Template:File refers to a file
  • $SVN is the fullpath to the location of your KDE subversion checkout


Unlike KDE3, KDE4 applications will be built with the help of CMake. The easiest way to port your autotools system to CMake is with the help of the am2cmake script which can be found in the cmake/scripts directory of the kdesdk module. This will create a series of Template:File files alongside your old buildsystem files.


A portion of porting your code to KDE4 is simply renaming of class names and header files. Since it would be rather tedious to change all these by hand, there is a handy script in the scripts/qt4 directory of kdesdk called This will scan all your files and create a diff output which can then be used to patch your code.

Once that simple code substitution has been done, you will still have to go through your code to port to, for example, the new KAction API. Documentation about all API changes is kept in the KDE4PORTING.html file in the kdelibs module.

Qt Designer UI Files

Qt designer ".ui" files created using Qt3 must be converted to the new Qt4 format. This can be done using the uic3 program available from your Qt4 installation.

% $SVN/trunk/qt-copy/bin/uic3 -convert file.ui > foo.ui % mv foo.ui file.ui

Or, if you prefer a graphical tool, you can use Qt4's designer program

% $SVN/trunk/qt-copy/bin/designer file.ui (you can save file.ui over top itself, or save to a new file)

Beware, the conversion process loses any custom slots, table columns, etc. So, you may need to put some stuff back by hand.

You should also run the fixuifiles program from the kdesdk module: % $SVN/trunk/KDE/kdesdk/scripts/fixuifiles


Instead of DCOP in KDE3, KDE4 now uses D-Bus for its interprocess communication.

A guide on how to port the DCOP parts to D-Bus is available in the PORTING-TO-DBUS.txt file in the kdelibs module.

Several D-Bus tutorials are located in the Tutorials section.

Do's and Don'ts

  • Do NOT use the old-style socket classes.
  • Do NOT use QPtrList, and in general, setAutoDelete()
  • Do NOT use of raster operations.
  • Do NOT do code painting on widgets outside paint events.
  • Try not to use QHBox, QVBox, QGrid. Prefer layouts instead.
  • Do NOT play with frames of groupboxes, labels, or lineedits to fake a different widget. Use the appropriate widget instead. e.g., instead of setting a label to have a sunken lineedit border, how about using a readonly KLineEdit instead? And instead of using a KLineEdit without a border for a copyable widget, use KActiveLabel.
  • Do NOT use a groupbox without border to group widgets! Just use a layout.



Other Help

  • #kde4-devel on

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V.Legal