https://github.com/jaytwolab/useoldqt5inqt6
Use old Qt5 in Qt6 :kr: Qt6에서 구형 Qt5 사용하기
https://github.com/jaytwolab/useoldqt5inqt6
cpp qt qt5 qt6
Last synced: about 2 months ago
JSON representation
Use old Qt5 in Qt6 :kr: Qt6에서 구형 Qt5 사용하기
- Host: GitHub
- URL: https://github.com/jaytwolab/useoldqt5inqt6
- Owner: JayTwoLab
- License: mit
- Created: 2020-12-05T06:12:13.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2020-12-27T09:38:21.000Z (over 5 years ago)
- Last Synced: 2025-03-28T12:32:22.088Z (about 1 year ago)
- Topics: cpp, qt, qt5, qt6
- Language: C++
- Homepage:
- Size: 10.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# UseOldQt5inQt6
## Use Old Qt5 in Qt6
:one: Set qmake(.pro) or cmake(CMakeList.txt).
- For qmake(.pro)
```qmake
QT += core5compat
```
- For cmake(CMakeList.txt)
```cmake
PUBLIC_LIBRARIES
Qt::Core5Compat
```
:two: Check old Qt5 class.
| Qt 5 Class | Qt 6 Replacement |
| ---------------- | ------------------ |
| QLinkedList | std::list * |
| QRegExp | QRegularExpression |
| QStringRef | QStringView |
| QXmlSimpleReader | QXmlStreamReader |
| QTextCodec | QStringConverter |
| QTextEncoder | QStringEncoder |
| QTextDecoder | QStringDecoder |
- If you are planning a long-term upgrade, Upgrade old class to a new version of new class.
## Code
- UseOldQt5inQt6.pro
```pro
# UseOldQt5inQt6.pro
message( 'Qt major version : ' $$QT_MAJOR_VERSION ) # test in Qt6.
##################################
# TODO: Append for old Qt5 code.
QT += core5compat
##################################
QT -= gui
CONFIG += c++11
CONFIG += console
CONFIG -= app_bundle
# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
```
- main.cpp
```cpp
// main.cpp
#include
#include
#include
#include
#include // Qt 5.10 or higher version
//----------------------
// #include // you may use this header.
#include // QStringRef : Qt4.3 ~ Qt5
//----------------------
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
#if QT_VERSION_MAJOR == 6
// custom code for Qt 6 or higer version
qDebug() << "Qt version is six.";
#endif
#if QT_VERSION_MAJOR == 5
// custom code for Qt 5
qDebug() << "Qt version is five.";
#endif
#if QT_VERSION_MAJOR == 4
// ? Are you still in use?
#endif
QString qstr("Hello, Qt5 in Qt6.");
// Qt5 class ( QStringRef )
QStringRef sref( &qstr );
qDebug() << "QStringRef" << sref;
// Qt6 class ( QStringView )
QStringView sv( qstr );
qDebug() << "QStringView" << sv;
return 0; // return a.exec();
}
```
## :kr: Qt6에서 구형 Qt5 사용하기
- (Korean Blog) https://j2doll.tistory.com/671