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 把 QML 应用程序移植到 Qt5 .
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:
.qml
files and replace the
import QtQuick 1.0
statements with
import QtQuick 2.3
.
import QtQuick.XmlListModel 2.0
statement to
qml/common/RssModel.qml
.
注意:
XmlListModel
is part of a submodule under
QtQuick
and it must be imported explicitly in order to use it.
qmlapplicationviewer/qmlapplicationviewer.h
:
#include <QtDeclarative/QDeclarativeView>
with
#include <QQuickView>
.
QDeclarativeView
with
QQuickView
in the class declaration for
QmlApplicationViewer
.
QmlApplicationViewer
constructor from
QWidget
to
QWindow
.
qmlapplicationviewer/qmlapplicationviewer.cpp
:
QtCore
and
QtDeclarative
include statements with these:
#include <QCoreApplication> #include <QDir> #include <QFileInfo> #include <QQmlComponent> #include <QQmlEngine> #include <QQmlContext> #include <QDebug>
QWidget
with
QWindow
,和
QDeclarativeView
with
QQuickView
.
#if defined(Q_OS_SYMBIAN)
and
#endif
macros as Symbian platform is not supported in Qt 5.
#if QT_VERSION < 0x040702
and
#else
,和
#endif // QT_VERSION < 0x040702
macros towards the end.
Once you see the application running, check whether it behaves as expected. Here is a snapshot of the application running on Ubuntu v12.04: