Transition from Qt 4.x to Qt5: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
No edit summary
 
No edit summary
Line 1: Line 1:
=The Transition from Qt 4.x to Qt 5=
[[Category:Developing_Qt]]


The transition from Qt 4.x to Qt 5 is not expected to be significant. However, the “modularization” of the Qt code base requires some amount of changes to project configuration, such as use of “headers”, and configuration of project build settings (such as changes to the *.pro files).
[toc align_right="yes" depth="2"]


Qt Creator (master) is compiled using Qt 4 and Qt 5; you can refer to its sources to get an overview of what is required to port an application and keep the sources backwards compatible to Qt 4.
= The Transition from Qt 4.x to Qt 5 =


==QtWidgets as a Separate Module==
The transition from Qt 4.x to Qt 5 is not expected to be significant. However, the "modularization" of the Qt code base requires some amount of changes to project configuration, such as use of "headers", and configuration of project build settings (such as changes to the '''.pro files).
<br />Qt Creator (master) is compiled using Qt 4 and Qt 5; you can refer to its sources to get an overview of what is required to port an application and keep the sources backwards compatible to Qt 4.
<br />h2. QtWidgets as a Separate Module
<br />h3. example compile time errors<br /><code><br />error: QMainWindow: No such file or directory<br />error: QToolButton: No such file or directory<br />error: QWidget: No such file or directory<br /></code>
<br />h3. Solution
<br />Add this in your'''.pro file:


===example compile time errors===
<code><br />QT ''= widgets<br /></code>
<br />Change all instances of
<br /><code><br />#include &lt;QtGui&amp;gt;<br /></code>
<br />to
<br /><code><br />#include &lt;QtWidgets&amp;gt;<br /></code>
<br />The code should work now, though sometimes you may require to be more explicit:
<br /><code><br />#include &lt;QtWidgets/QToolButton&amp;gt;<br /></code>
<br />h2. QtWebKitWidgets is also a separate module:
<br />h3. example compile time errors<br /><code><br />error: invalid use of incomplete type 'class QWebFrame'<br />error: forward declaration of 'class QWebFrame'<br /></code>
<br />h3. Solution
<br />Add this in your *.pro file:
<br /><code><br />QT''= webkitwidgets<br /></code>


===Solution===
'''Note''': when you have QT ''= webkitwidgets you don't need QT''= widgets


Add this in your *.pro file:
In addition, replace all instances of


Change all instances of
<code><br />#include &lt;QtWebKit&amp;gt;<br /></code>


to
to


The code should work now, though sometimes you may require to be more explicit:
<code><br />#include &lt;QtWebKitWidgets&amp;gt;<br /></code>


==QtWebKitWidgets is also a separate module:==
You can try this by porting a &quot;WYSISWYG html editor&amp;quot;:http://qt.gitorious.org/qt-labs/graphics-dojo/trees/c8d0c381b994d7417863832929cc4c3f710f2db5/htmleditor from Qt 4 to Qt 5.


===example compile time errors===
== QPrinter Doesn't Work ==


===Solution===
If your code has the following lines:
 
Add this in your *.pro file:
 
'''Note''': when you have QT += webkitwidgets you don’t need QT += widgets
 
In addition, replace all instances of
 
to
 
You can try this by porting a [http://qt.gitorious.org/qt-labs/graphics-dojo/trees/c8d0c381b994d7417863832929cc4c3f710f2db5/htmleditor <span class="caps">WYSISWYG</span> html editor] ''[qt.gitorious.org]'' from Qt 4 to Qt 5.
 
==QPrinter Doesn’t Work==


If your code has the following lines:
<code><br />#include &lt;QPrinter&amp;gt;<br />#include &lt;QPrintDialog&amp;gt;<br /></code>


add the following to your project file:
add the following to your project file:


Again, sometimes it may not work and you would need to be explicit:
<code><br />QT ''= printsupport<br /></code>
<br />Again, sometimes it may not work and you would need to be explicit:
<br /><code><br />#include &lt;QtPrintSupport/QPrinter&amp;gt;<br />#include &lt;QtPrintSupport/QPrintDialog&amp;gt;<br /></code>
<br />h2. toAscii() and fromAscii() Methods are deprecated
<br />Replace all instances of
<br /><code><br />fromAscii()<br />toAscii()<br /></code>
<br />to<br /><code><br />fromLatin1()<br />toLatin1()<br /></code>
<br />For example, given the Qt 4 code<br /><code><br />QByteArray configfileti = TMP_Config.toAscii();<br /></code>
<br />you would change to<br /><code><br />QByteArray configfileti = TMP_Config.toLatin1();<br /></code>
<br />h2. QCoreApplication::UnicodeUTF8 is deprecated
<br />This enum type used to define the 8-bit encoding of character string arguments to translate(). This enum is now obsolete and UTF-8 will be used in all cases. So remove all instances of QCoreApplication::UnicodeUTF8. For example:
<br /><code><br />Href_Gui-&gt;setWindowTitle(QApplication::translate(&quot;Href_Gui&amp;quot;, &quot;Url / www&amp;quot;, 0, QApplication::UnicodeUTF8));<br />label-&gt;setText(QApplication::translate(&quot;Href_Gui&amp;quot;, &quot;Text:&quot;, 0, QApplication::UnicodeUTF8));<br />label_2-&gt;setText(QApplication::translate(&quot;Href_Gui&amp;quot;, &quot;Url:&quot;, 0, QApplication::UnicodeUTF8));<br />label_3-&gt;setText(QApplication::translate(&quot;Href_Gui&amp;quot;, &quot;Target / Name:&quot;, 0, QApplication::UnicodeUTF8));<br /></code>
<br />to
<br /><code><br />Href_Gui-&gt;setWindowTitle(QApplication::translate(&quot;Href_Gui&amp;quot;, &quot;Url / www&amp;quot;, 0));<br />label-&gt;setText(QApplication::translate(&quot;Href_Gui&amp;quot;, &quot;Text:&quot;, 0));<br />label_2-&gt;setText(QApplication::translate(&quot;Href_Gui&amp;quot;, &quot;Url:&quot;, 0));<br />label_3-&gt;setText(QApplication::translate(&quot;Href_Gui&amp;quot;, &quot;Target / Name:&quot;, 0));<br /></code>
<br />h2. QWorkspace is deprecated
<br />This class is obsolete and was replaced by the QMdiArea class in Qt 4.3. In Qt 5 QWorkspace has been removed. The new class has a similar API to QWorkspace and porting it only involved changing the names of a few methods, signals, and slots.
<br />replace
<br /><code>#include &lt;QWorkspace&amp;gt;<br /></code>
<br />with
<br /><code>#include &lt;QMdiArea&amp;gt;<br /></code>
<br />h2. QDrag Problems
<br />Apps that has drop and drag functionality will need some tweaking. A line such as
<br /><code><br />QDrag '''drag = new QDrag(event-&gt;widget());<br /></code>
<br />in Qt 5 will generate the error
<br /><code><br />error: no matching function for call to 'QDrag::QDrag(QWidget''')'<br /></code>
<br />To fix this add among the includes:
<br /><code><br />#include &lt;QWidget&amp;gt;<br /></code>
<br />h2. qFindChildren is deprecated
<br />An error will pop of this fashion:<br /><code><br />error: 'qFindChildren' was not declared in this scope<br /></code>
<br />To solve this you replace qFindChildren with findChildren, for example in
<br /><code><br />toString(const QObject* obj, int indentLevel) const {<br />[…]<br /> /* Query over QObjects '''/<br /> if (m_children) {<br /> QList&amp;lt;QObject'''&gt; childlist = qFindChildren&amp;lt;QObject*&gt;(obj, QString());<br />[…]<br /></code>
<br />replace
<br /><code><br />QList&amp;lt;QObject*&gt; childlist = qFindChildren&amp;lt;QObject*&gt;(obj, QString());<br /></code>
<br />with
<br /><code><br />QList&amp;lt;QObject*&gt; childlist = obj-&gt;findChildren&amp;lt;QObject*&gt;(QString());<br /></code>


==toAscii() and fromAscii() Methods are deprecated==
<br />&quot;source&amp;quot;:https://bugs.webkit.org/attachment.cgi?id=82025&amp;amp;action=diff
<br />h2. qVariantValue is deprecated
<br />Your compiler will say<br /><code><br />error: 'qVariantValue' was not declared in this scope<br /></code>
<br />This function is equivalent to QVariant::value&amp;lt;T&amp;gt;(value). Therefore if given a QVariant val rewrite the line<br /><code><br />QTime t = qVariantValue&amp;lt;QTime&amp;gt;(val);<br /></code>
<br />to
<br /><code><br />QTime t = val.value&amp;lt;QTime&amp;gt;();<br /></code>
<br />This QTime enclosed in the angled brackets lets the compiler know what QVariant will return. However, if the variable is not a QVariable the type enclosed in the angled brackets should not be used(doing so will result in a vague compile time error). So given that m_color is of type QColor you will rewrite
<br /><code><br />s.setValue(&quot;color/favorite&amp;quot;, qVariantValue&amp;lt;QColor&amp;gt;(m_color));<br /></code>
<br />to
<br /><code><br />s.setValue(&quot;color/favorite&amp;quot;, m_color.value());<br /></code>
<br />&quot;source&amp;quot;:http://stackoverflow.com/questions/14919867/qvariantvalue-is-qt-deprecated-what-is-the-replacement
<br />h2. qVariantCanConvert is deprecated
<br />replace
<br /><code><br />Q_ASSERT(qVariantCanConvert&amp;lt;QString&amp;gt;(variant));<br />Q_ASSERT(qVariantCanConvert&amp;lt;QSize&amp;gt;(variant));<br />Q_ASSERT(qVariantCanConvert&amp;lt;QFont&amp;gt;(fontVariant));<br /></code>
<br />with
<br /><code><br />Q_ASSERT(variant.canConvert(QMetaType::QString));<br />Q_ASSERT(variant.canConvert(QMetaType::QSize));<br />Q_ASSERT(fontVariant.canConvert(QMetaType::QFont));<br /></code>
<br />h2. Qt::escape is deprecated
<br /><code><br />error: 'escape' is not a member of 'Qt'<br /></code>
<br />So you would change the following block:
<br /><code><br /> if (result == QString())<br /> result = Qt::escape(val.toString());<br /> else<br /> result = Qt::escape(result);<br /> return result;<br /></code>
<br />to
<br /><code><br /> if (result == QString())<br /> result = QString(val.toString()).toHtmlEscaped();<br /> else<br /> result = QString(result).toHtmlEscaped();<br /> return result;<br /></code>
<br />this procedure can be automated by a &quot;porting tool&amp;quot;:http://www.kdab.com/automated-porting-from-qt-4-to-qt-5/ from KDAB.
<br />h2. QDesktopServices::storageLocation deprecated
<br /><code><br />error: 'storageLocation' is not a member of 'QDesktopServices'<br />error: 'DataLocation' is not a member of 'QDesktopServices'<br /></code>
<br />Use QStandardPaths::StandardLocation:
<br /><code><br />QString path = s.value(&quot;db.path&amp;quot;, QDesktopServices::storageLocation(QDesktopServices::DataLocation)).toString();<br /></code>
<br />to
<br /><code><br />QString path = s.value(&quot;db.path&amp;quot;, QStandardPaths::standardLocations(QStandardPaths::DataLocation)).toString();<br /></code>
<br />&quot;source&amp;quot;:http://doc.qt.io/qt-5.0/qtgui/qdesktopservices-obsolete.html
<br />h2. CONFIG''=qtestlib is deprecated


Replace all instances of
If you have the above line in your project file the compiler will warn you in the compile window, nonetheless the code will still run as usual:


to <br />
<code><br />Project WARNING: CONFIG+=qtestlib is deprecated. Use QT+=testlib instead.<br /></code>


For example, given the Qt 4 code<br />
== QWeakPointer quirks ==


you would change to <br />
A code block like


==QCoreApplication::UnicodeUTF8 is deprecated==
<code><br />quint64 decodedPointer = line.toULongLong();<br />MetaData* md = reinterpret_cast&amp;amp;lt;MetaData*&amp;gt;(decodedPointer);<br />QWeakPointer&amp;amp;lt;MetaData&amp;amp;gt; wp(md);<br /></code>


This enum type used to define the 8-bit encoding of character string arguments to translate(). This enum is now obsolete and <span class="caps">UTF</span>-8 will be used in all cases. So remove all instances of QCoreApplication::UnicodeUTF8. For example:
results in
 
to


==QWorkspace is deprecated==
<code><br />error: no matching function for call to 'QWeakPointer&amp;amp;lt;MetaData&amp;amp;gt;::QWeakPointer(MetaData*&amp;)'<br /></code>
 
This class is obsolete and was replaced by the QMdiArea class in Qt 4.3. In Qt 5 QWorkspace has been removed. The new class has a similar <span class="caps">API</span> to QWorkspace and porting it only involved changing the names of a few methods, signals, and slots.
 
replace
 
with
 
==QDrag Problems==
 
Apps that has drop and drag functionality will need some tweaking. A line such as
 
in Qt 5 will generate the error
 
To fix this add among the includes:
 
==qFindChildren is deprecated==
 
An error will pop of this fashion:<br />
 
To solve this you replace qFindChildren with findChildren, for example in
 
replace
 
with
 
[https://bugs.webkit.org/attachment.cgi?id=82025&action=diff source] ''[bugs.webkit.org]''
 
==qVariantValue is deprecated==
 
Your compiler will say<br />
 
This function is equivalent to QVariant::value&lt;T&gt;(value). Therefore if given a QVariant val rewrite the line<br />
 
to
 
This QTime enclosed in the angled brackets lets the compiler know what QVariant will return. However, if the variable is not a QVariable the type enclosed in the angled brackets should not be used(doing so will result in a vague compile time error). So given that m_color is of type QColor you will rewrite
 
to
 
[http://stackoverflow.com/questions/14919867/qvariantvalue-is-qt-deprecated-what-is-the-replacement source] ''[stackoverflow.com]''
 
==qVariantCanConvert is deprecated==
 
replace
 
with
 
==Qt::escape is deprecated==
 
So you would change the following block:
 
to
 
this procedure can be automated by a [http://www.kdab.com/automated-porting-from-qt-4-to-qt-5/ porting tool] ''[kdab.com]'' from <span class="caps">KDAB</span>.
 
==QDesktopServices::storageLocation deprecated==
 
Use QStandardPaths::StandardLocation:
 
to
 
[http://doc.qt.io/qt-5.0/qtgui/qdesktopservices-obsolete.html source] ''[qt.io]''
 
==<span class="caps">CONFIG</span>+=qtestlib is deprecated==
 
If you have the above line in your project file the compiler will warn you in the compile window, nonetheless the code will still run as usual:
 
==QWeakPointer quirks==
 
A code block like
 
results in


To fix this add to the project file:
To fix this add to the project file:


[http://forum.qt.io/viewthread/27510 source] ''[qt.io]''
<code><br />DEFINES ''= QT_DISABLE_DEPRECATED_BEFORE=0<br /></code>
 
<br />&quot;source&amp;quot;:http://forum.qt.io/viewthread/27510
==QtConcurrent Library is Missing?==
<br />h2. QtConcurrent Library is Missing?
 
<br /><code><br />C:5.0.2\5.0.2\mingw47_32\include\QtConcurrent\qtconcurrentthreadengine.h:133: error: undefined reference to `_imp___ZN12QtConcurrent16ThreadEngineBaseD2Ev'<br /></code>
In Qt 4, QtConcurrent was part of QtCore, so there was no need to include specific headers. This is no longer the case with Qt 5. If your source code have lines like
<br />In Qt 4, QtConcurrent was part of QtCore, so there was no need to include specific headers. This is no longer the case with Qt 5. If your source code have lines like
 
<br /><code><br />m_current = QtConcurrent::blockingMappedReduced(slices, functor, stitchReduce, QtConcurrent::UnorderedReduce );<br /></code>
You will need to include the header:
<br />You will need to include the header:
 
<br /><code><br />#include &lt;QtConcurrent/QtConcurrent&amp;gt;<br /></code>
and add the following line to your project file:
<br />and add the following line to your project file:
<br /><code><br />QT''= concurrent<br /></code>


==Fixing #include&lt;&gt; Headers==
== Fixing #include&amp;lt;&gt; Headers ==


A Perl script “fixqt4headers.pl” exists in qtbase/bin/. that should be run on source code using Qt that corrects the #include&lt;&gt; directives for Qt components to also consider the module name.
A Perl script &quot;fixqt4headers.pl&amp;quot; exists in qtbase/bin/. that should be run on source code using Qt that corrects the #include&amp;lt;&gt; directives for Qt components to also consider the module name.


==Plugin loading==
== Plugin loading ==


The Q_EXPORT_PLUGIN,Q_EXPORT_PLUGIN2 macros have been deprecated in favor of the new Q_PLUGIN_METADATA macro. The advantage of the new system is that it allows Qt to query the metadata for the plugin without actually dlopen’ing it. This greatly improves performance and reliability of the plugin system.
The Q_EXPORT_PLUGIN,Q_EXPORT_PLUGIN2 macros have been deprecated in favor of the new Q_PLUGIN_METADATA macro. The advantage of the new system is that it allows Qt to query the metadata for the plugin without actually dlopen'ing it. This greatly improves performance and reliability of the plugin system.


The new Q_PLUGIN_METADATA macro is included next to the Q_OBJECT macro in the QObject derived class that is returned when loading the plugin. It contains the plugins <span class="caps">IID</span> and a filename pointing to a json file containing the metadata for the plugin. The json file is compiled into the plugin and does not need to be installed.
The new Q_PLUGIN_METADATA macro is included next to the Q_OBJECT macro in the QObject derived class that is returned when loading the plugin. It contains the plugins IID and a filename pointing to a json file containing the metadata for the plugin. The json file is compiled into the plugin and does not need to be installed.


An example on how to change your plugins can be found by looking at the patch that changes the Gif image format plugin, see http://qt.gitorious.org/qt/qtbase/commit/963b4c1647299fd023ddbe7c4a25ac404e303c5d .
An example on how to change your plugins can be found by looking at the patch that changes the Gif image format plugin, see http://qt.gitorious.org/qt/qtbase/commit/963b4c1647299fd023ddbe7c4a25ac404e303c5d .


==Deploying to systems without C++11==
== Deploying to systems without C+''11
 
<br />When Qt is built from source code on a system with C11 installed, the Qt libraries/frameworks are linked against the system's C11 library (libc). This means that the Qt libraries/frameworks are not deployable to systems without C11 installed (such as out-of-the-box Mac OS X 10.6). To be able to deploy to systems that only support the older C''+ standard (libstdc+''), build Qt from source code with the -no-c11 configure option.  
When Qt is built from source code on a system with C++11 installed, the Qt libraries/frameworks are linked against the system’s C++11 library (libc++). This means that the Qt libraries/frameworks are not deployable to systems without C++11 installed (such as out-of-the-box Mac OS X 10.6). To be able to deploy to systems that only support the older C++ standard (libstdc++), build Qt from source code with the -no-c++11 configure option.
<br />h2. QTimer is no longer accurate to the millisecond by default
 
<br />QTimer has now 3 accuracy types, with a new default behaviour:<br />* The new default type is Qt::CoarseTimer which, to reduce power/CPU consumption, allow ''5% difference'' between requested time and actual one, and even ''allow the timer to fire before'' the requested time.<br />* The former one is Qt::PreciseTimer (to the millisecond, never before the requested time).<br />* A third one is Qt::VeryCoarseTimer and allow a 1 second difference
==QTimer is no longer accurate to the millisecond by default==
<br />h2. QUrl addQueryItem moved to QUrlQuery
 
<br />If you have:<br /><code><br />QUrl url;<br />// …<br />url.addQueryItem(key, value);<br /></code>
QTimer has now 3 accuracy types, with a new default behaviour:
<br />You will want to change it to<br /><code><br />QUrl url;<br />QUrlQuery urlQuery;<br />// …<br />urlQuery.addQueryItem(key, value);
 
<br />url.setUrlQuery(urlQuery);<br /></code>
* The new default type is Qt::CoarseTimer which, to reduce power/CPU consumption, allow ''5% difference'' between requested time and actual one, and even ''allow the timer to fire before'' the requested time.
<br />h2. QAbstractItemModel changes
* The former one is Qt::PreciseTimer (to the millisecond, never before the requested time).
<br /><code><br />void reset()<br />void setRoleNames(const QHash&amp;lt;int, QByteArray&amp;gt; &amp; roleNames)<br /></code><br />both have changed and are now protected.
* A third one is Qt::VeryCoarseTimer and allow a 1 second difference
<br />See &quot;Compatibility Members for QAbstractItemModel&amp;quot;:http://doc.qt.io/qt-5/qabstractitemmodel-compat.html#reset
 
<br />h2. Recommended Reading
==QUrl addQueryItem moved to QUrlQuery==
<br />* &quot;C''+ API Changes&amp;quot;:http://doc.qt.io/qt-5.0/qtdoc/sourcebreaks.html<br />* &quot;The porting guide&amp;quot;:http://doc.qt.io/qt-5.0/qtdoc/portingguide.html<br />* &quot;Porting Desktop Applications from Qt 4 to Qt 5&amp;quot;:http://blog.ics.com/2013/01/porting-desktop-applications-from-qt-4-to-qt-5.html#.UVDeLReGqSr<br />* &quot;Porting from Qt 4 to Qt 5&amp;quot;:http://www.kdab.com/porting-from-qt-4-to-qt-5/<br />* &quot;Automated porting from Qt 4 to Qt 5&amp;quot;:http://www.kdab.com/automated-porting-from-qt-4-to-qt-5/ ==
 
If you have:<br />
 
You will want to change it to<br />
 
==QAbstractItemModel changes==
 
both have changed and are now protected.
 
See [http://doc.qt.io/qt-5/qabstractitemmodel-compat.html#reset Compatibility Members for QAbstractItemModel] ''[qt.io]''
 
==Recommended Reading==
 
* [http://doc.qt.io/qt-5.0/qtdoc/sourcebreaks.html C++ <span class="caps">API</span> Changes] ''[qt.io]''
* [http://doc.qt.io/qt-5.0/qtdoc/portingguide.html The porting guide] ''[qt.io]''
* [http://blog.ics.com/2013/01/porting-desktop-applications-from-qt-4-to-qt-5.html#.UVDeLReGqSr Porting Desktop Applications from Qt 4 to Qt 5] ''[blog.ics.com]''
* [http://www.kdab.com/porting-from-qt-4-to-qt-5/ Porting from Qt 4 to Qt 5] ''[kdab.com]''
* [http://www.kdab.com/automated-porting-from-qt-4-to-qt-5/ Automated porting from Qt 4 to Qt 5] ''[kdab.com]''
 
===Categories:===
 
* [[:Category:Developing Qt|Developing_Qt]]
* [[:Category:Developing with Qt|Developing_with_Qt]]

Revision as of 12:45, 23 February 2015


[toc align_right="yes&quot; depth="2&quot;]

The Transition from Qt 4.x to Qt 5

The transition from Qt 4.x to Qt 5 is not expected to be significant. However, the "modularization&quot; of the Qt code base requires some amount of changes to project configuration, such as use of "headers&quot;, and configuration of project build settings (such as changes to the .pro files).
Qt Creator (master) is compiled using Qt 4 and Qt 5; you can refer to its sources to get an overview of what is required to port an application and keep the sources backwards compatible to Qt 4.
h2. QtWidgets as a Separate Module


h3. example compile time errors

<br />error: QMainWindow: No such file or directory<br />error: QToolButton: No such file or directory<br />error: QWidget: No such file or directory<br />


h3. Solution
Add this in your.pro file:

<br />QT ''= widgets<br />


Change all instances of


<br />#include &lt;QtGui&amp;gt;<br />


to


<br />#include &lt;QtWidgets&amp;gt;<br />


The code should work now, though sometimes you may require to be more explicit:


<br />#include &lt;QtWidgets/QToolButton&amp;gt;<br />


h2. QtWebKitWidgets is also a separate module:


h3. example compile time errors

<br />error: invalid use of incomplete type 'class QWebFrame'<br />error: forward declaration of 'class QWebFrame'<br />


h3. Solution
Add this in your *.pro file:


<br />QT''= webkitwidgets<br />

Note: when you have QT = webkitwidgets you don't need QT= widgets

In addition, replace all instances of

<br />#include &lt;QtWebKit&amp;gt;<br />

to

<br />#include &lt;QtWebKitWidgets&amp;gt;<br />

You can try this by porting a "WYSISWYG html editor&quot;:http://qt.gitorious.org/qt-labs/graphics-dojo/trees/c8d0c381b994d7417863832929cc4c3f710f2db5/htmleditor from Qt 4 to Qt 5.

QPrinter Doesn't Work

If your code has the following lines:

<br />#include &lt;QPrinter&amp;gt;<br />#include &lt;QPrintDialog&amp;gt;<br />

add the following to your project file:

<br />QT ''= printsupport<br />


Again, sometimes it may not work and you would need to be explicit:


<br />#include &lt;QtPrintSupport/QPrinter&amp;gt;<br />#include &lt;QtPrintSupport/QPrintDialog&amp;gt;<br />


h2. toAscii() and fromAscii() Methods are deprecated
Replace all instances of


<br />fromAscii()<br />toAscii()<br />


to

<br />fromLatin1()<br />toLatin1()<br />


For example, given the Qt 4 code

<br />QByteArray configfileti = TMP_Config.toAscii();<br />


you would change to

<br />QByteArray configfileti = TMP_Config.toLatin1();<br />


h2. QCoreApplication::UnicodeUTF8 is deprecated
This enum type used to define the 8-bit encoding of character string arguments to translate(). This enum is now obsolete and UTF-8 will be used in all cases. So remove all instances of QCoreApplication::UnicodeUTF8. For example:


<br />Href_Gui-&gt;setWindowTitle(QApplication::translate(&quot;Href_Gui&amp;quot;, &quot;Url / www&amp;quot;, 0, QApplication::UnicodeUTF8));<br />label-&gt;setText(QApplication::translate(&quot;Href_Gui&amp;quot;, &quot;Text:&quot;, 0, QApplication::UnicodeUTF8));<br />label_2-&gt;setText(QApplication::translate(&quot;Href_Gui&amp;quot;, &quot;Url:&quot;, 0, QApplication::UnicodeUTF8));<br />label_3-&gt;setText(QApplication::translate(&quot;Href_Gui&amp;quot;, &quot;Target / Name:&quot;, 0, QApplication::UnicodeUTF8));<br />


to


<br />Href_Gui-&gt;setWindowTitle(QApplication::translate(&quot;Href_Gui&amp;quot;, &quot;Url / www&amp;quot;, 0));<br />label-&gt;setText(QApplication::translate(&quot;Href_Gui&amp;quot;, &quot;Text:&quot;, 0));<br />label_2-&gt;setText(QApplication::translate(&quot;Href_Gui&amp;quot;, &quot;Url:&quot;, 0));<br />label_3-&gt;setText(QApplication::translate(&quot;Href_Gui&amp;quot;, &quot;Target / Name:&quot;, 0));<br />


h2. QWorkspace is deprecated
This class is obsolete and was replaced by the QMdiArea class in Qt 4.3. In Qt 5 QWorkspace has been removed. The new class has a similar API to QWorkspace and porting it only involved changing the names of a few methods, signals, and slots.
replace


#include &lt;QWorkspace&amp;gt;<br />


with


#include &lt;QMdiArea&amp;gt;<br />


h2. QDrag Problems
Apps that has drop and drag functionality will need some tweaking. A line such as


<br />QDrag '''drag = new QDrag(event-&gt;widget());<br />


in Qt 5 will generate the error


<br />error: no matching function for call to 'QDrag::QDrag(QWidget''')'<br />


To fix this add among the includes:


<br />#include &lt;QWidget&amp;gt;<br />


h2. qFindChildren is deprecated


An error will pop of this fashion:

<br />error: 'qFindChildren' was not declared in this scope<br />


To solve this you replace qFindChildren with findChildren, for example in


<br />toString(const QObject* obj, int indentLevel) const {<br />[]<br /> /* Query over QObjects '''/<br /> if (m_children) {<br /> QList&amp;lt;QObject'''&gt; childlist = qFindChildren&amp;lt;QObject*&gt;(obj, QString());<br />[…]<br />


replace


<br />QList&amp;lt;QObject*&gt; childlist = qFindChildren&amp;lt;QObject*&gt;(obj, QString());<br />


with


<br />QList&amp;lt;QObject*&gt; childlist = obj-&gt;findChildren&amp;lt;QObject*&gt;(QString());<br />


"source&quot;:https://bugs.webkit.org/attachment.cgi?id=82025&amp;action=diff
h2. qVariantValue is deprecated


Your compiler will say

<br />error: 'qVariantValue' was not declared in this scope<br />


This function is equivalent to QVariant::value&lt;T&gt;(value). Therefore if given a QVariant val rewrite the line

<br />QTime t = qVariantValue&amp;lt;QTime&amp;gt;(val);<br />


to


<br />QTime t = val.value&amp;lt;QTime&amp;gt;();<br />


This QTime enclosed in the angled brackets lets the compiler know what QVariant will return. However, if the variable is not a QVariable the type enclosed in the angled brackets should not be used(doing so will result in a vague compile time error). So given that m_color is of type QColor you will rewrite


<br />s.setValue(&quot;color/favorite&amp;quot;, qVariantValue&amp;lt;QColor&amp;gt;(m_color));<br />


to


<br />s.setValue(&quot;color/favorite&amp;quot;, m_color.value());<br />


"source&quot;:http://stackoverflow.com/questions/14919867/qvariantvalue-is-qt-deprecated-what-is-the-replacement
h2. qVariantCanConvert is deprecated
replace


<br />Q_ASSERT(qVariantCanConvert&amp;lt;QString&amp;gt;(variant));<br />Q_ASSERT(qVariantCanConvert&amp;lt;QSize&amp;gt;(variant));<br />Q_ASSERT(qVariantCanConvert&amp;lt;QFont&amp;gt;(fontVariant));<br />


with


<br />Q_ASSERT(variant.canConvert(QMetaType::QString));<br />Q_ASSERT(variant.canConvert(QMetaType::QSize));<br />Q_ASSERT(fontVariant.canConvert(QMetaType::QFont));<br />


h2. Qt::escape is deprecated


<br />error: 'escape' is not a member of 'Qt'<br />


So you would change the following block:


<br /> if (result == QString())<br /> result = Qt::escape(val.toString());<br /> else<br /> result = Qt::escape(result);<br /> return result;<br />


to


<br /> if (result == QString())<br /> result = QString(val.toString()).toHtmlEscaped();<br /> else<br /> result = QString(result).toHtmlEscaped();<br /> return result;<br />


this procedure can be automated by a "porting tool&quot;:http://www.kdab.com/automated-porting-from-qt-4-to-qt-5/ from KDAB.
h2. QDesktopServices::storageLocation deprecated


<br />error: 'storageLocation' is not a member of 'QDesktopServices'<br />error: 'DataLocation' is not a member of 'QDesktopServices'<br />


Use QStandardPaths::StandardLocation:


<br />QString path = s.value(&quot;db.path&amp;quot;, QDesktopServices::storageLocation(QDesktopServices::DataLocation)).toString();<br />


to


<br />QString path = s.value(&quot;db.path&amp;quot;, QStandardPaths::standardLocations(QStandardPaths::DataLocation)).toString();<br />


"source&quot;:http://doc.qt.io/qt-5.0/qtgui/qdesktopservices-obsolete.html
h2. CONFIG=qtestlib is deprecated

If you have the above line in your project file the compiler will warn you in the compile window, nonetheless the code will still run as usual:

<br />Project WARNING: CONFIG+=qtestlib is deprecated. Use QT+=testlib instead.<br />

QWeakPointer quirks

A code block like

<br />quint64 decodedPointer = line.toULongLong();<br />MetaData* md = reinterpret_cast&amp;amp;lt;MetaData*&amp;gt;(decodedPointer);<br />QWeakPointer&amp;amp;lt;MetaData&amp;amp;gt; wp(md);<br />

results in

<br />error: no matching function for call to 'QWeakPointer&amp;amp;lt;MetaData&amp;amp;gt;::QWeakPointer(MetaData*&amp;)'<br />

To fix this add to the project file:

<br />DEFINES ''= QT_DISABLE_DEPRECATED_BEFORE=0<br />


"source&quot;:http://forum.qt.io/viewthread/27510
h2. QtConcurrent Library is Missing?


<br />C:5.0.2\5.0.2\mingw47_32\include\QtConcurrent\qtconcurrentthreadengine.h:133: error: undefined reference to `_imp___ZN12QtConcurrent16ThreadEngineBaseD2Ev'<br />


In Qt 4, QtConcurrent was part of QtCore, so there was no need to include specific headers. This is no longer the case with Qt 5. If your source code have lines like


<br />m_current = QtConcurrent::blockingMappedReduced(slices, functor, stitchReduce, QtConcurrent::UnorderedReduce );<br />


You will need to include the header:


<br />#include &lt;QtConcurrent/QtConcurrent&amp;gt;<br />


and add the following line to your project file:


<br />QT''= concurrent<br />

Fixing #include&lt;> Headers

A Perl script "fixqt4headers.pl&quot; exists in qtbase/bin/. that should be run on source code using Qt that corrects the #include&lt;> directives for Qt components to also consider the module name.

Plugin loading

The Q_EXPORT_PLUGIN,Q_EXPORT_PLUGIN2 macros have been deprecated in favor of the new Q_PLUGIN_METADATA macro. The advantage of the new system is that it allows Qt to query the metadata for the plugin without actually dlopen'ing it. This greatly improves performance and reliability of the plugin system.

The new Q_PLUGIN_METADATA macro is included next to the Q_OBJECT macro in the QObject derived class that is returned when loading the plugin. It contains the plugins IID and a filename pointing to a json file containing the metadata for the plugin. The json file is compiled into the plugin and does not need to be installed.

An example on how to change your plugins can be found by looking at the patch that changes the Gif image format plugin, see http://qt.gitorious.org/qt/qtbase/commit/963b4c1647299fd023ddbe7c4a25ac404e303c5d .

== Deploying to systems without C+11
When Qt is built from source code on a system with C11 installed, the Qt libraries/frameworks are linked against the system's C11 library (libc). This means that the Qt libraries/frameworks are not deployable to systems without C11 installed (such as out-of-the-box Mac OS X 10.6). To be able to deploy to systems that only support the older C+ standard (libstdc+), build Qt from source code with the -no-c11 configure option.
h2. QTimer is no longer accurate to the millisecond by default
QTimer has now 3 accuracy types, with a new default behaviour:
* The new default type is Qt::CoarseTimer which, to reduce power/CPU consumption, allow 5% difference between requested time and actual one, and even allow the timer to fire before the requested time.
* The former one is Qt::PreciseTimer (to the millisecond, never before the requested time).
* A third one is Qt::VeryCoarseTimer and allow a 1 second difference
h2. QUrl addQueryItem moved to QUrlQuery


If you have:

<br />QUrl url;<br />// …<br />url.addQueryItem(key, value);<br />


You will want to change it to

<br />QUrl url;<br />QUrlQuery urlQuery;<br />// …<br />urlQuery.addQueryItem(key, value);
<br />url.setUrlQuery(urlQuery);<br />


h2. QAbstractItemModel changes


<br />void reset()<br />void setRoleNames(const QHash&amp;lt;int, QByteArray&amp;gt; &amp; roleNames)<br />


both have changed and are now protected.


See "Compatibility Members for QAbstractItemModel&quot;:http://doc.qt.io/qt-5/qabstractitemmodel-compat.html#reset
h2. Recommended Reading
* "C+ API Changes&quot;:http://doc.qt.io/qt-5.0/qtdoc/sourcebreaks.html
* "The porting guide&quot;:http://doc.qt.io/qt-5.0/qtdoc/portingguide.html
* "Porting Desktop Applications from Qt 4 to Qt 5&quot;:http://blog.ics.com/2013/01/porting-desktop-applications-from-qt-4-to-qt-5.html#.UVDeLReGqSr
* "Porting from Qt 4 to Qt 5&quot;:http://www.kdab.com/porting-from-qt-4-to-qt-5/
* "Automated porting from Qt 4 to Qt 5&quot;:http://www.kdab.com/automated-porting-from-qt-4-to-qt-5/ ==