blob: 6f565805b911330a2f44f8e19fec0f547eff3b94 [file] [log] [blame]
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the documentation of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:FDL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Free Documentation License Usage
** Alternatively, this file may be used under the terms of the GNU Free
** Documentation License version 1.3 as published by the Free Software
** Foundation and appearing in the file included in the packaging of
** this file. Please review the following information to ensure
** the GNU Free Documentation License version 1.3 requirements
** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
** $QT_END_LICENSE$
**
****************************************************************************/
/*!
\page portingcppapp.html
\title Porting C++ Applications to Qt 5
\brief Provides instructions to migrate a Qt 4 C++ application 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 \l{Animated Tiles Example}{Animated Tiles} application to Qt 5:
\list 1
\li Open the Animated Tiles project using Qt Creator.
\li Edit \c {main.cpp} and replace the \c {#include <QtGui>} instance with
\c {#include <QtWidgets>}.
The Perl-script \c fixqt4headers.pl can be used to scan the source files
of a project and perform the replacements.
\li Edit the \c {animatedtiles.pro} and add \c {QT += widgets} towards the
end of the file.
\note \l{Qt GUI} is included by default in all Qt applications unless excluded using the \c {QT -= gui} directive in the \c{qmake} project file.
\li Save the changes and run the application.
\endlist
Once you see the application running, check whether it behaves as expected.
\image animatedtiles_snapshot.png "A snapshot of the \c animatedtiles application running on Ubuntu v12.04"
It is also possible to keep the project compiling with Qt 4 and Qt 5. This requires:
\list 1
\li Omitting the module name from all includes by running the
\c fixqt4headers.pl script with the \c --strip-modules option.
\li Adding scopes depending on the version of Qt to the \c{.pro} files:
\code
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
\endcode
\li Introducing \c #if scopes around code using modified API:
\code
#if QT_VERSION >= 0x050000
headerView->setSectionResizeMode(QHeaderView::ResizeToContents);
#else
headerView->setResizeMode(QHeaderView::ResizeToContents);
#endif
\endcode
\endlist
if you are using Qt WebKit, see
\l{Porting from Qt WebKit to Qt WebEngine}{Qt WebKit to Qt WebEngine} porting
instructions.
\section1 Related Topics
\list
\li \l {C++ API Changes}
\li \l {Porting QML Applications to Qt 5 Example}
\li \l {Qt Examples And Tutorials}
\endlist
*/