Porting QML Applications to Qt 5 Example
The new version of Qt Quick in Qt 5 brings in some changes to the way QML applications are developed. For the complete list of changes that affect existing QML applications, refer to Porting QML Applications to Qt 5.
This topic will walk through the porting process to make the flickr Qt 4 QML demo work on Qt 5. If you have the SDK based on Qt 4.8 installed, you can find this demo application under <install_dir_root>/Examples/4.x/declarative/demos/.
The flickr application is a complete application that comes with a launcher.
Follow these step-by-step instructions to make the flickr Qt 4 QML application work on Qt 5:
- Edit all the .qml files and replace import QtQuick 1.0 statements with import QtQuick 2.0.
- Add the additional import QtQuick.XmlListModel 2.0 statement to qml/common/RssModel.qml.
Note: XmlListModel is part of a submodule under QtQuick and it must be imported explicitly to use it.
- Make the following changes to qmlapplicationviewer/qmlapplicationviewer.h:
- Replace the #include <QtDeclarative/QDeclarativeView> with #include <QQuickView>.
- Replace QDeclarativeView with QQuickView in the class declaration for QmlApplicationViewer.
- Replace the parameter for QmlApplicationViewer constructor from QWidget to QWindow.
- Make the following changes to qmlapplicationviewer/qmlapplicationviewer.cpp:
- Replace all the QtCore and QtDeclarative include statements with these:
#include <QCoreApplication> #include <QDir> #include <QFileInfo> #include <QQmlComponent> #include <QQmlEngine> #include <QQmlContext> #include <QDebug>
- Replace all instances of QWidget with QWindow, and QDeclarativeView with QQuickView.
- Remove the code between #if defined(Q_OS_SYMBIAN) and #endif macros as Symbian platform is not supported in Qt 5.
- Remove the code between #if QT_VERSION < 0x040702 and #else, and #endif // QT_VERSION < 0x040702 macros towards the end.
- Replace all the QtCore and QtDeclarative include statements with these:
- Run the qmake and make utilities to build the application.
Note: Ensure that the PATH environment variable is pointing to the Qt 5 binaries and libraries directories, before running qmake.
Run the flickr application to see whether it behaves as expected. Here is a snapshot of the application running on Ubuntu v12.04:
Related Topics
Porting QML Applications to Qt 5