This article is reproduced from http://hi.baidu.com/xchinux/item/9044d8ce986accbb0d0a7b87
First, to change a QT4 project to QT5 encountered problems
The QT4 project was previously developed using Qt4.7.4 MSVC2008 because of the use of OWC10 (Office Web components), Using the MSVC compiler would not be able to upgrade to qt4.8.x and QT5, so the compiler was converted to MINGW4.7,QT upgrade to 4.8.4. Today the QT 5.0.1-mingw precompiled version is released, so take it practiced hand and upgrade it to QT5 to reduce the number of QT versions that exist in the system. The following problems are encountered:
1. Since QT5 has moved most of the desktop parts to the QT widgets module, add the following line in. Pro
QT + = Widgets
2. The OWC10 used in the program, the use of ACTIVEQT, the original practice is in. Pro Plus config + = Qaxcontainer, now need to change to
QT + = Axcontainer
Of course, the original config + = Qaxcontainer will also be removed
3. To fully use the C++11 feature, add the following line to the. Pro
CONFIG + = c++11
4. In the source file, all involved in the original Qtgui in the visual parts, all to modify the header file reference, or add qtwidgets header file, such as:
#include <QtGui/QPushButton> change to #include <QPushButton> or #include <QtWidgets/QPushButton>
In places where you used # include <QtGui>, add #include <QtWidgets>
5. Since Qt5 removes the qtextcodec::setcodecforcstrings () function, there are two ways of modifying it in the case of directly writing Chinese characters in CPP:
A) If the previous source file encoding is GBK, you need to use the Qstring::fromlocal8bit () function to enclose the original kanji, or convert the source file encoding directly to UTF-8 (the disadvantage is that the MSVC compiler is not easy to use). I use the qstring::fromlocal8bit () to invoke the way (of course, another convenient function or macro to handle)
b) If the previous source file encoding is UTF-8, then nothing moves.
6. Previously used Qdesktopservices::storagelocation (QDESKTOPSERVICES::XXXX) to obtain some system directories, now you want to change to
Qstandardpaths::writablelocation (QSTANDARDPATHS::XXXX)
7. When Qfiledialog::getsavefilename () was previously called, if the file name is specified under Windows Using Native dialog, the file name will be displayed correctly, and now QT5 will not display correctly. So the latter two parameters are added, namely qfiledialog::getsavefilename (xxx, xxx, xxx, xxx, 0, Qfiledialog::D ontusenativedialog), so it is normal, It's just that the dialog box is not a system form.
8. Also, QT5 solves the problem with the Ui_qaxselect.h file. In the Qt4 era, when using ACTIVEQT, the old hint does not have this file, it is necessary to find the source code manual UIC Qaxselect.ui > ui_qaxselect.h to generate a bit, Qt5 the problem solved.
9. Use to print related classes, Qt5 separate into the Qtprintsupport module, so the header file # include <qtprintsupport>, in. Pro to add qt + = Printsupport
10. Using WebKit related visual parts such as Qwebpage, QT5 is placed in the Qtwebkitwidgets module alone, so add header file # include <qtwebkitwidgets> in. Pro Add qt + = Webkitwidgets
One. Qt4 in Cleanlooks, Plastique, CDE, motif and other theme styles No, the new fusion, okay, the problem is that my project framework uses the Cleanlooks theme style and then adds a custom style sheet, which is good, after the upgrade Qt5 , some of which are inconsistent or defective with windowsvista or fusion and have to be adjusted. Therefore, to the topic style relies on the more serious procedures, to measure whether to upgrade to QT5.
In the. Pro file, the target in QT4 (Qmake v2) is not filled in, then it automatically takes the. Pro file name, while in Qt5 (Qmake v3) This target has to be written.
Q_WS_XX macros are not available, use Q_OS_XX instead.
As for the C++11 support connection signal and slot can not use slot, signal macro problem, now do not change it, although the new method to remove the two macros, and strengthen the type check, but also added the class name and A & symbol, first lazy not move it.
--------------------------------------------------------------------------------------------
Ii. changes in QT5.0
1. QT5 added JSON support
2. QT5 supported platforms are: Desktop platform: Windows, linux/x11, Mac OS X
Embedded platform: Embedded Linux (DIRECTFB, Eglfs, KMS, Wayland), WIndows Embedded (Compact and Standard), real-time OS (QNX, VxWorks, I ntegrity)
Mobile platforms: Android, IOS, Windows 8 (WinRT), BlackBerry 103. QtQuick2,
Many new QML Elements have been added, requiring OpenGL (ES) or DirectX support, as well as graphic effects, multimedia enhancement
4. Qguiapplication and Qwindow were added for Qtquick, and if the traditional qwidgrets-based program is developed, the previous qapplication and Qmainwindow are still used
5. The new Qtgui contains only a small number of GUI core content, the original Qt4 in the Qtgui contained in the majority of widgets, Itemview, Graphicsview related content has been moved to the Qtwidgets module, so in Qt5, If you develop QTQUICK2 application, you can remove the Qtwidgets module, it is not necessary.
6. Separate Qtmultimedia module, can be used in C + + and QML, support audio, video, radio, MediaPlayer, camera and other interfaces
7. Bearer Managemtn is added to the Qtnetwork module to control the system (network, etc.) connection status
8. The QTQML module provides basic QML engines, types, objects, and other C + + support related to it, while the Qtquick module provides basic QML Elements.
Overall: The upgrade from QT4 to QT5 is relatively smooth, and will not be as good as Qt3 to QT4 as the equivalent of re-written again. And the Qtquick upgrade is also stable (C + + in the main program to change), but also some of the original qtmobility content moved to the QT5. Start supporting the mainstream mobile platform (Android, IOS, Windows 8 (WinRT), BlackBerry), Symbian is no longer updated, let it go away. As for meego/sailfish, it should be categorized into linux/x11, and the embedded platform adds QNX (in fact, BlackBerry 10 is also QNX-based). http://blog.csdn.net/ccf19881030/article/details/11992967
Upgrade an QT4 project to a problem encountered by QT5 (13 methods)