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/
.
Follow these step-by-step instructions to port the flickr Qt 4 QML application work to Qt 5:
- Open the flickr project using Qt Creator.
- Edit all the
.qml
files and replace theimport QtQuick 1.0
statements withimport QtQuick 2.3
. - Add the additional
import QtQuick.XmlListModel 2.0
statement toqml/common/RssModel.qml
.Note: XmlListModel is part of a submodule under
QtQuick
and it must be imported explicitly in order to use it. - Make the following changes to
qmlapplicationviewer/qmlapplicationviewer.h
:- Replace the
#include <QtDeclarative/QDeclarativeView>
with#include <QQuickView>
. - Replace
QDeclarativeView
withQQuickView
in the class declaration forQmlApplicationViewer
. - Replace the parameter for
QmlApplicationViewer
constructor fromQWidget
toQWindow
.
- Replace the
- Make the following changes to
qmlapplicationviewer/qmlapplicationviewer.cpp
:- Replace all the
QtCore
andQtDeclarative
include statements with these:#include <QCoreApplication> #include <QDir> #include <QFileInfo> #include <QQmlComponent> #include <QQmlEngine> #include <QQmlContext> #include <QDebug>
- Replace all instances of
QWidget
withQWindow
, andQDeclarativeView
withQQuickView
. - 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
- Save changes to the project and run the application.
Once you see the application running, check whether it behaves as expected. Here is a snapshot of the application running on Ubuntu v12.04:
Related Topics
© 2024 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.