Porting C++ Applications to Qt 5
This topic talks about the Qt Widgets changes in Qt 5. The following step-by-step instructions take you through the changes required to port the Animated Tiles application to Qt 5:
- Open the Animated Tiles project using Qt Creator.
main.cppand replace the
#include <QtGui>instance with
#include <QtWidgets>. The Perl-script
fixqt4headers.plcan be used to scan the source files of a project and perform the replacements.
- Edit the
QT += widgetstowards the end of the file.
Note: Qt GUI is included by default in all Qt applications unless excluded using the
QT -= guidirective in the
- Save the changes and run the application.
Once you see the application running, check whether it behaves as expected.
It is also possible to keep the project compiling with Qt 4 and Qt 5. This requires:
- Omitting the module name from all includes by running the
fixqt4headers.plscript with the
- Adding scopes depending on the version of Qt to the
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
#ifscopes around code using modified API:
© 2018 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.