Qt5 compatibility

This commit squashes all the changes in the Qt5 branch
relative to master.

Backward compatibility with Qt4 is retained.

Original authors:

- Philip Kaufmann <phil.kaufmann@t-online.de>
- Jonas Schnelli <jonas.schnelli@include7.ch>
Merge pull request #2721 from laanwj/2013_05_qt5

Qt5 compatibility