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:
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.
For example, if your source code is located in /path/to/src then:
% cd /path/to/src
There is also a tool that looks in your resulting Template:File files for potential problems. This tool called cmakelint.pl is located in $SVN/trunk/kde/kdesdk/scripts. Use it like so:
% cd /path/to/src
% $SVN/trunk/KDE/kdesdk/scripts/cmakelint.pl CMakeLists.txt
Or, to run it over your entire source directory:
% cd /path/to/src
% find . -name CMakeLists.txt | xargs $SVN/trunk/KDE/kdesdk/scripts/cmakelint.pl
An overview of the Qt3 to Qt4 transition is provided in Trolltech's "Moving from Qt 3 to Qt 4" paper. This document provides an excellent overview into the major functionality changes with Qt4 and is highly recommended.
The follow-on "Porting to Qt 4" page gives an amazingly detailed description of the porting process, along with a list of the changes in the classes and functions.
These documents describe a tool provided by Trolltech called qt3to4 that can help port the Qt parts of your code from Qt3 to Qt4, using compatibility functions. Run qt3to4 as follows:
% $SVN/trunk/qt-copy/bin/qt3to4 [options] <Infile>, [Infile], ...
Infile can be a source file or a project file. If you specify a project file, ending with '.pro' or '.pri', qt3to4 will port all files specified in that project.
For more information, run qt3to4 with the "--help" option or visit the "qt3to4-The Qt 3 to 4 Porting Tool" page.
Much of the porting effort consists of simply renaming 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 adapt-to-kde4-api.pl. 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 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:
Instead of DCOP in KDE3, KDE4 now uses D-Bus for its interprocess communication. Porting from DCOP to D-Bus is a large topic that is covered in great detail in the Porting to D-Bus tutorial.
For more information, please see all our D-Bus tutorials.
To create your ".pot" file, copy the commands from the 'messages' rule in your projects Template:File to a shell script called Template:File. You may assume the same variables ($PREPARETIPS, $XGETTEXT, $podir, etc.) still exist, but keep in mind the differences between Makefile and shell script syntax.
For example, the 'messages' creation rule:
rm -f tips.cpp $(PREPARETIPS) > tips.cpp $(XGETTEXT) -ktranslate *.cpp *.h -o $(podir)/kmail.pot rm -f tips.cpp
becomes the following Template:File script:
$PREPARETIPS > tips.cpp $XGETTEXT -ktranslate *.cpp *.h -o $podir/kmail.pot rm -f tips.cpp