KDE-Apps.org Applications for the KDE-Desktop 
 GTK-Apps.org Applications using the GTK Toolkit 
 GnomeFiles.org Applications for GNOME 
 MeeGo-Central.org Applications for MeeGo 
 CLI-Apps.org Command Line Applications 
 Qt-Apps.org Free Qt Applications 
 Qt-Prop.org Proprietary Qt Applications 
 Maemo-Apps.org Applications for the Maemo Plattform 
 Java-Apps.org Free Java Applications 
 eyeOS-Apps.org Free eyeOS Applications 
 Wine-Apps.org Wine Applications 
 Server-Apps.org Server Applications 
 apps.ownCloud.com ownCloud Applications 
 KDE-Look.org Artwork for the KDE-Desktop 
 GNOME-Look.org Artwork for the GNOME-Desktop 
 Xfce-Look.org Artwork for the Xfce-Desktop 
 Box-Look.org Artwork for your Windowmanager 
 E17-Stuff.org Artwork for Enlightenment 
 Beryl-Themes.org Artwork for the Beryl Windowmanager 
 Compiz-Themes.org Artwork for the Compiz Windowmanager 
 EDE-Look.org Themes for your EDE Desktop 
 Debian-Art.org Stuff for Debian 
 Gentoo-Art.org Artwork for Gentoo Linux 
 SUSE-Art.org Artwork for openSUSE 
 Ubuntu-Art.org Artwork for Ubuntu 
 Kubuntu-Art.org Artwork for Kubuntu 
 LinuxMint-Art.org Artwork for Linux Mint 
 Arch-Stuff.org Art And Stuff for Arch Linux 
 Frugalware-Art.org Themes for Frugalware 
 Fedora-Art.org Artwork for Fedora Linux 
 Mandriva-Art.org Artwork for Mandriva Linux 
 KDE-Files.org Files for KDE Applications 
 OpenTemplate.org Documents for OpenOffice.org
 GIMPStuff.org Files for GIMP
 InkscapeStuff.org Files for Inkscape
 ScribusStuff.org Files for Scribus
 BlenderStuff.org Textures and Objects for Blender
 VLC-Addons.org Themes and Extensions for VLC
 KDE-Help.org Support for your KDE Desktop 
 GNOME-Help.org Support for your GNOME Desktop 
 Xfce-Help.org Support for your Xfce Desktop 
openDesktop.orgopenDesktop.org:   Applications   Artwork   Linux Distributions   Documents    LinuxDaily.com    Linux42.org    OpenSkillz.com   

- News . 
click to vote up

David Sugar: Qt 5 migration notes

Published Jan 27 2013 via RSS

I wanted to write a little about our effort to migrate to Qt5. It has been said that Qt5 is 99% compatible with Qt4 sources, and this indeed is true. However, it is the 1% that is still often not explained or sufficiently documented. Furthermore, in my particular case, I wanted to migrate code that can then build under both Qt4 and Qt5, and to do so with cmake, which is not explained at all.

My reasons for this are simple. I often build a binary package that works on different distribution releases. I do not want to go through the trouble of separately maintaining different package metas for each and every debian or ubuntu release. In the future Qt5 will displace Qt4, but things like Ubuntu LTS and Debian stable releases that use Qt4 will continue to be maintained for years after this. Hence I want to make sure this happens without having to split either my packaging or my sources.

In Qt itself, source practices like not using _WS OS defines, or already identified depreciated features, make it easy to recompile Qt4 applications with Qt5. There is one important exception. Things that used to use <QX11Info> are now entirely gone in Qt5.

It happens I was using QX11Info for one thing; I needed the X11 display handle so that I could call libxss, the screensaver library. I wanted to know when the xscreensaver was active and to track input idle time, and I did not find a better way to do this other than calling the X11 screensaver extension lib. If someone knows a better way I would be happy to hear it.

However, it is easy to come up with a valid alternative. What I eventually came up with was something like:

#if QT_VERSION >= 0x050000
#include <qpa/qplatformnativeinterface.h>
#include <QX11Info>
#include <X11/extensions/scrnsaver.h>

To get the correct headers whether Qt4 or Qt5. And to get the native display handle:

#if QT_VERSION >= 0x050000
QPlatformNativeInterface *native = QGuiApplication::platformNativeInterface();
return false;
Display *display = static_cast<Display *>(native->nativeResourceForWindow("display", NULL));
Display *display = QX11Info::display();

CMake was a little tricker. First, the Qt5 specific macros are different from the Qt4 ones. Also, they are not in regular use yet. In any case, I wanted a CMakeLists.txt that behaved correctly for both Qt4 and Qt5. I eventually found I could extend the existing Qt4 cmake macros to support Qt5 directly.

find_package(Qt4 4.8.0 REQUIRED)
set(QT5_FOUND true)

The idea of adding the extra include paths for Qt5 relative is because the standard Qt4 paths already are correct for the cmake ran qmake instance being invoked. Adding the extra paths has no effect on Qt4. Also, the extra linkage for Qt5 has to be accounted for:


Indeed this all works and will produce a CMakeLists.txt that does the correct thing for both Qt4 and Qt5, at least for applications that of course use widgets. One additional problem is in includes.

In Qt4 one needed to only

#include <QtGui>
to get all the Qt widget classes included. Sloppy, but sometimes useful for simplicity. In Qt5, one has to now use that and
#include <QWidget>
. However, this no longer seems to include ALL the classes like in Qt4, just "most" of them. The rest have to be manually included. In particular things like QDialog, surprisingly, were left out. However, adding the additional includes do not in any way break Qt4. So again, we end up with code that configures and compiles, both for Qt4 and Qt5, and actually pretty painlessly like claimed.

BackRead original postSend to a friend

Add comment

Add comment
Show all posts


Do you like or dislike Ubuntu Unity?
 Yes, unity is alien technology!
 It is less confusing than Gnome 3 default, shell.
 Granny thinks it is much more usable than Gnome 2
 Canonical is embarrasing itself with this split project
 Gnome 3 default shell is much better
 I dislike Unity, Gnome 3 default shell is alien technology!
 None of the above, I like the 2Gb for free and Apple alike behavior. Will post a comment instead


 Who we are
More about us
Frequently Asked Questions
Updates on identi.ca
Updates on Twitter
Facebook App
Content RSS   
News RSS   
Discussion RSS   
Events RSS   

Add Artwork
Public API
About KDE-Look.org
Legal Notice
Spreadshirt Shop
CafePress Shop
Sponsor us
Report Abuse

Copyright 2001-2014 KDE-Look.org Team  
All rights reserved. KDE-Look.org is not liable for any content or goods on this site.
All contributors are responsible for the lawfulness of their uploads.
KDE and K Desktop Environment are trademarks of KDE e.V.