From ee5f88c130e413dd919e447af2ff50f3766013e3 Mon Sep 17 00:00:00 2001 From: jared Date: Thu, 27 Aug 2020 09:19:56 +0800 Subject: [PATCH] update for compatibility Qt 6 --- 3rdparty/TaoCommon/Logger/logger.cpp | 10 +++++++++- TaoQuick.pro | 4 +--- examples/TaoQuickShow/Qml/main.qml | 2 +- examples/TaoQuickShow/Src/TaoView.cpp | 5 ++++- examples/TaoQuickShow/Src/TaoView.h | 4 ++++ examples/TaoQuickShow/Src/Trans.cpp | 4 ++-- examples/TaoQuickShow/Src/main.cpp | 5 +++-- 7 files changed, 24 insertions(+), 10 deletions(-) diff --git a/3rdparty/TaoCommon/Logger/logger.cpp b/3rdparty/TaoCommon/Logger/logger.cpp index 7c7f0be..fa80be5 100644 --- a/3rdparty/TaoCommon/Logger/logger.cpp +++ b/3rdparty/TaoCommon/Logger/logger.cpp @@ -6,7 +6,7 @@ #include #include #include - +#include #include #ifdef Q_OS_WIN @@ -81,7 +81,11 @@ namespace Logger bool exist = file.exists(); file.open(QIODevice::WriteOnly | QIODevice::Append); textStream.setDevice(&file); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + textStream.setEncoding(QStringConverter::Utf8); +#else textStream.setCodec("UTF-8"); +#endif if (!exist) { textStream << logTemplate << "\r\n"; @@ -127,7 +131,11 @@ namespace Logger bool exist = file.exists(); file.open(QIODevice::WriteOnly | QIODevice::Append); QTextStream textStream(&file); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + textStream.setEncoding(QStringConverter::Utf8); +#else textStream.setCodec("UTF-8"); +#endif if (!exist) { textStream << logTemplate << "\r\n"; diff --git a/TaoQuick.pro b/TaoQuick.pro index 29136bd..55ef327 100644 --- a/TaoQuick.pro +++ b/TaoQuick.pro @@ -1,6 +1,4 @@ -lessThan(QT_MAJOR_VERSION, 5) { - error("current Qt version $$QT_VERSION, this project need grather than 5.12.0") -} else: lessThan(QT_MINOR_VERSION, 12){ +lessThan(QT_MAJOR_VERSION, 5): lessThan(QT_MINOR_VERSION, 12) { error("current Qt version $$QT_VERSION, this project need grather than 5.12.0") } diff --git a/examples/TaoQuickShow/Qml/main.qml b/examples/TaoQuickShow/Qml/main.qml index 23f9de8..8fbef6b 100644 --- a/examples/TaoQuickShow/Qml/main.qml +++ b/examples/TaoQuickShow/Qml/main.qml @@ -2,7 +2,7 @@ import QtQuick 2.12 import QtQuick.Controls 2.12 import QtGraphicalEffects 1.0 -Item { +Rectangle { id: rootView width: 1440 height: 900 diff --git a/examples/TaoQuickShow/Src/TaoView.cpp b/examples/TaoQuickShow/Src/TaoView.cpp index b1d5e98..574babc 100644 --- a/examples/TaoQuickShow/Src/TaoView.cpp +++ b/examples/TaoQuickShow/Src/TaoView.cpp @@ -94,8 +94,11 @@ void TaoView::setIsMax(bool isMax) #if WIN32 const long border_width = 6; - +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) +bool TaoView::nativeEvent(const QByteArray &eventType, void *message, qintptr *result) +#else bool TaoView::nativeEvent(const QByteArray &eventType, void *message, long *result) +#endif { if (!result) { return false; diff --git a/examples/TaoQuickShow/Src/TaoView.h b/examples/TaoQuickShow/Src/TaoView.h index 6a3b5b8..5081629 100644 --- a/examples/TaoQuickShow/Src/TaoView.h +++ b/examples/TaoQuickShow/Src/TaoView.h @@ -25,8 +25,12 @@ signals: protected: #if WIN32 +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + bool nativeEvent(const QByteArray &eventType, void *message, qintptr *result) override; +#else bool nativeEvent(const QByteArray &eventType, void *message, long *result) override; #endif +#endif private: bool m_isMax; }; diff --git a/examples/TaoQuickShow/Src/Trans.cpp b/examples/TaoQuickShow/Src/Trans.cpp index 5310d70..867aaea 100644 --- a/examples/TaoQuickShow/Src/Trans.cpp +++ b/examples/TaoQuickShow/Src/Trans.cpp @@ -38,7 +38,7 @@ void Trans::loadFolder(const QString& folder) // res.waitForFinished(); initEnglish(); - auto langs = m_map.uniqueKeys(); + auto langs = m_map.keys(); if (langs.contains(cChineseStr)) { langs.removeAll(cChineseStr); langs.push_front(cChineseStr); @@ -96,7 +96,7 @@ void Trans::initEnglish() } else { map = m_map.value(m_map.keys().first()); } - for (auto key : map.uniqueKeys()) { + for (auto key : map.keys()) { m_map[cEnglisthStr][key] = key; } } diff --git a/examples/TaoQuickShow/Src/main.cpp b/examples/TaoQuickShow/Src/main.cpp index b78d72a..aa350d1 100644 --- a/examples/TaoQuickShow/Src/main.cpp +++ b/examples/TaoQuickShow/Src/main.cpp @@ -23,7 +23,8 @@ int main(int argc, char** argv) prepareApp(); QGuiApplication app(argc, argv); Logger::initLog(); - qWarning() << "appPath" << app.applicationDirPath(); + const auto appPath = QDir(app.applicationDirPath()).absolutePath(); + qWarning() << "appPath" << appPath; TaoView view; @@ -39,7 +40,7 @@ int main(int argc, char** argv) view.rootContext()->setContextProperty("qmlPath", qmlPath); view.rootContext()->setContextProperty("imgPath", imgPath); view.rootContext()->setContextProperty("contentsPath", contentsPath); - view.rootContext()->setContextProperty("appPath", app.applicationDirPath()); + view.rootContext()->setContextProperty("appPath", appPath); view.rootContext()->setContextProperty("view", &view); const QUrl url(qmlPath + QStringLiteral("main.qml"));