From 13ee598de74fbcb23dcfa1c6ce62f0615fcc6c72 Mon Sep 17 00:00:00 2001 From: zhanghongyuan Date: Tue, 2 Dec 2025 13:59:35 +0800 Subject: [PATCH] refactor(qt): add automatic Qt version detection and update compatibility code Replace hardcoded Qt version with automatic detection that supports both Qt5 and Qt6. Update all Qt version-specific code to use unified APIs, replacing QRegExp with QRegularExpression and removing version conditionals throughout the codebase. --- CMakeLists.txt | 18 +++++-- deepin-devicemanager/CMakeLists.txt | 9 ++-- .../src/DeviceManager/DeviceInfo.cpp | 22 +------- .../src/DeviceManager/DeviceInput.cpp | 38 ------------- .../src/DeviceManager/DeviceManager.cpp | 4 -- .../src/DeviceManager/DeviceMonitor.cpp | 54 +++---------------- .../src/DeviceManager/DeviceStorage.cpp | 52 +++++++----------- .../src/Tool/ThreadExecXrandr.cpp | 2 +- .../src/Widget/DetailTreeView.cpp | 1 - .../src/Widget/DriverListView.cpp | 6 ++- deepin-devicemanager/src/commondefine.h | 15 ------ 11 files changed, 52 insertions(+), 169 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fca1cfef..3deee94b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,8 +16,20 @@ if(CMAKE_BUILD_TYPE STREQUAL "Debug") add_definitions(-DDISABLE_POLKIT) endif() -# 设置 QT_VERSION 变量 -set(QT_VERSION_MAJOR 6) +# 自动检测系统中的Qt版本 +if(NOT DEFINED QT_VERSION_MAJOR) + # 首先尝试查找Qt6 + find_package(Qt6 QUIET) + if(Qt6_FOUND) + set(QT_VERSION_MAJOR 6) + message("Found Qt6, using Qt version 6") + else() + set(QT_VERSION_MAJOR 5) + message("Found Qt5, using Qt version 5") + endif() +else() + message("Using manually specified QT_VERSION_MAJOR: ${QT_VERSION_MAJOR}") +endif() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,-z,relro -Wl,-z,now") @@ -28,4 +40,4 @@ add_subdirectory(${CMAKE_SOURCE_DIR}/deepin-devicemanager-server) if(CMAKE_COVERAGE_ARG STREQUAL "CMAKE_COVERAGE_ARG_ON") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -Wall -fprofile-arcs -ftest-coverage") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Wall -fprofile-arcs -ftest-coverage") -endif() \ No newline at end of file +endif() diff --git a/deepin-devicemanager/CMakeLists.txt b/deepin-devicemanager/CMakeLists.txt index 4138654d..da978795 100644 --- a/deepin-devicemanager/CMakeLists.txt +++ b/deepin-devicemanager/CMakeLists.txt @@ -145,19 +145,18 @@ SET_QT_VERSION() if(${QT_VERSION_MAJOR} EQUAL 6) find_package(QApt-qt6 REQUIRED) - include_directories(${QApt-qt6_INCLUDE_DIRS}) + include_directories(${QApt-qt6_INCLUDE_DIRS}) + include_directories(${Qt6Gui_PRIVATE_INCLUDE_DIRS}) set(QAPT_LIB QApt-qt6) elseif(${QT_VERSION_MAJOR} EQUAL 5) find_package(QApt REQUIRED) include_directories(${QApt_INCLUDE_DIRS}) + include_directories(${Qt5Gui_PRIVATE_INCLUDE_DIRS}) set(QAPT_LIB QApt) else() message(FATAL_ERROR "Unsupported QT_VERSION_MAJOR: ${QT_VERSION_MAJOR}") endif() -#include_directories(${Qt5Gui_PRIVATE_INCLUDE_DIRS}) -include_directories(${Qt6Gui_PRIVATE_INCLUDE_DIRS}) - # Tell CMake to create the executable add_executable(${PROJECT_NAME} ${SRC_CPP} ${SRC_H} ${APP_QRC}) target_include_directories(${APP_BIN_NAME} PUBLIC ${DtkWidget_INCLUDE_DIRS} ${OBJECT_BINARY_DIR}) @@ -222,4 +221,4 @@ endif() # Test--------deepin-devicemanager if (CMAKE_COVERAGE_ARG STREQUAL "CMAKE_COVERAGE_ARG_ON") add_subdirectory(./tests) -endif() \ No newline at end of file +endif() diff --git a/deepin-devicemanager/src/DeviceManager/DeviceInfo.cpp b/deepin-devicemanager/src/DeviceManager/DeviceInfo.cpp index 5d47713b..40d6f2d6 100644 --- a/deepin-devicemanager/src/DeviceManager/DeviceInfo.cpp +++ b/deepin-devicemanager/src/DeviceManager/DeviceInfo.cpp @@ -817,11 +817,7 @@ const QString DeviceBaseInfo::getDriverVersion() } foreach (QString out, outInfo.split("\n")) { -#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) - QStringList item = out.split(":", QString::SkipEmptyParts); -#else - QStringList item = out.split(":", Qt::SkipEmptyParts); -#endif + QStringList item = out.split(":", QT_SKIP_EMPTY_PARTS); if (!item.isEmpty() && "version" == item[0].trimmed()) { // qCDebug(appLog) << "Found driver version: " << item[1].trimmed(); return item[1].trimmed(); @@ -1077,7 +1073,6 @@ void DeviceBaseInfo::setHwinfoLshwKey(const QMap &mapInfo) << "o" << "p" << "q" << "r" << "s" << "t" << "u" << "v" << "w" << "x" << "y" << "z"; -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) QRegularExpression reg("([0-9a-zA-Z]+)-([0-9a-zA-Z]+)\\.([0-9a-zA-Z]+)"); QRegularExpressionMatch match = reg.match(words[0]); if (match.hasMatch()) { @@ -1086,27 +1081,12 @@ void DeviceBaseInfo::setHwinfoLshwKey(const QMap &mapInfo) int third = match.captured(3).toInt(); m_HwinfoToLshw = QString("usb@%1:%2.%3").arg(nums.at(first)).arg(nums.at(second)).arg(nums.at(third)); qCDebug(appLog) << "DeviceBaseInfo::setHwinfoLshwKey match"; - } else { - int first = chs[0].toInt(); - int second = chs[1].toInt(); - m_HwinfoToLshw = QString("usb@%1:%2").arg(nums.at(first)).arg(nums.at(second)); - qCDebug(appLog) << "DeviceBaseInfo::setHwinfoLshwKey not match"; - } -#else - QRegExp reg("([0-9a-zA-Z]+)-([0-9a-zA-Z]+)\\.([0-9a-zA-Z]+)"); - if (reg.exactMatch(words[0])) { - int first = reg.cap(1).toInt(); - int second = reg.cap(2).toInt(); - int third = reg.cap(3).toInt(); - m_HwinfoToLshw = QString("usb@%1:%2.%3").arg(nums.at(first)).arg(nums.at(second)).arg(nums.at(third)); - qCDebug(appLog) << "DeviceBaseInfo::setHwinfoLshwKey match"; } else { int first = chs[0].toInt(); int second = chs[1].toInt(); m_HwinfoToLshw = QString("usb@%1:%2").arg(nums.at(first)).arg(nums.at(second)); qCDebug(appLog) << "DeviceBaseInfo::setHwinfoLshwKey no match"; } -#endif } bool DeviceBaseInfo::matchToLshw(const QMap &mapInfo) diff --git a/deepin-devicemanager/src/DeviceManager/DeviceInput.cpp b/deepin-devicemanager/src/DeviceManager/DeviceInput.cpp index f34113de..010e3d4c 100644 --- a/deepin-devicemanager/src/DeviceManager/DeviceInput.cpp +++ b/deepin-devicemanager/src/DeviceManager/DeviceInput.cpp @@ -233,35 +233,17 @@ bool DeviceInput::getPS2Syspath(const QString &dfs) // qCDebug(appLog) << "Found sysfs line: " << sysfs; continue; } -#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) - QRegExp reg("H: Handlers=.*(event[0-9]{1,2}).*"); - if (reg.exactMatch(line)) { - event = reg.cap(1); - // qCDebug(appLog) << "Matched event using QRegExp: " << event; - } -#else QRegularExpression reg("H: Handlers=.*(event[0-9]{1,2}).*"); QRegularExpressionMatch match = reg.match(line); if (match.hasMatch()) { event = match.captured(1); // qCDebug(appLog) << "Matched event using QRegularExpression: " << event; } -#endif } if (!event.isEmpty() && !sysfs.isEmpty()) { // qCDebug(appLog) << "Event and sysfs are not empty. Checking for match."; if (event == eventdfs) { -#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) - QRegExp regfs; - if (sysfs.contains("i2c_designware")) - regfs = QRegExp("S: Sysfs=(.*)/input/input[0-9]{1,2}"); - else - regfs = QRegExp("S: Sysfs=(.*)/input[0-9]{1,2}"); - if (regfs.exactMatch(sysfs)) { - m_SysPath = regfs.cap(1); - } -#else QRegularExpression regfs; if (sysfs.contains("i2c_designware")) regfs = QRegularExpression("S: Sysfs=(.*)/input/input[0-9]{1,2}"); @@ -271,7 +253,6 @@ bool DeviceInput::getPS2Syspath(const QString &dfs) if (match.hasMatch()) { m_SysPath = match.captured(1); } -#endif } } } @@ -307,31 +288,18 @@ bool DeviceInput::isBluetoothDevice(const QString &dfs) Uniq = line; continue; } -#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) - QRegExp reg("H: Handlers=.*(event[0-9]{1,2}).*"); - if (reg.exactMatch(line)) { - event = reg.cap(1); - } -#else QRegularExpression reg("H: Handlers=.*(event[0-9]{1,2}).*"); QRegularExpressionMatch match = reg.match(line); if (match.hasMatch()) { event = match.captured(1); } -#endif } if (event == eventdfs) { -#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) - QRegExp regUniq(".*([0-9A-Z]{2}:[0-9A-Z]{2}:[0-9A-Z]{2}:[0-9A-Z]{2}:[0-9A-Z]{2}:[0-9A-Z]{2}).*"); - if (regUniq.exactMatch(Uniq)) { - QString id = regUniq.cap(1); -#else QRegularExpression regUniq(".*([0-9A-Z]{2}:[0-9A-Z]{2}:[0-9A-Z]{2}:[0-9A-Z]{2}:[0-9A-Z]{2}:[0-9A-Z]{2}).*"); QRegularExpressionMatch match = regUniq.match(Uniq); if (match.hasMatch()) { QString id = match.captured(1); -#endif QProcess process; process.start("hcitool con"); process.waitForFinished(-1); @@ -352,16 +320,10 @@ bool DeviceInput::isBluetoothDevice(const QString &dfs) QString DeviceInput::eventStrFromDeviceFiles(const QString &dfs) { qCDebug(appLog) << "eventStrFromDeviceFiles"; -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) QRegularExpression regdfs(".*(event[0-9]{1,2}).*"); QRegularExpressionMatch match = regdfs.match(dfs); if (match.hasMatch()) return match.captured(1); -#else - QRegExp regdfs(".*(event[0-9]{1,2}).*"); - if (regdfs.exactMatch(dfs)) - return regdfs.cap(1); -#endif qCDebug(appLog) << "eventStrFromDeviceFiles end"; return ""; } diff --git a/deepin-devicemanager/src/DeviceManager/DeviceManager.cpp b/deepin-devicemanager/src/DeviceManager/DeviceManager.cpp index 03910921..4eb26b48 100644 --- a/deepin-devicemanager/src/DeviceManager/DeviceManager.cpp +++ b/deepin-devicemanager/src/DeviceManager/DeviceManager.cpp @@ -1364,11 +1364,7 @@ DeviceBaseInfo *DeviceManager::getAudioDevice(const QString &path) DeviceAudio *audio = dynamic_cast(*it); QString tpath = audio->uniqueID(); // 判断该设备是否已经存在,1.1:1.1 -> 1.1:1.0 -#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) - if (audio && path == tpath.replace(QRegExp("[1-9]$"), "0")) { -#else if (audio && path == tpath.replace(QRegularExpression("[1-9]$"), "0")) { -#endif return *it; } QString syspath = audio->sysPath(); //remove dumplicate syspath diff --git a/deepin-devicemanager/src/DeviceManager/DeviceMonitor.cpp b/deepin-devicemanager/src/DeviceManager/DeviceMonitor.cpp index edce1d36..b53f9a14 100644 --- a/deepin-devicemanager/src/DeviceManager/DeviceMonitor.cpp +++ b/deepin-devicemanager/src/DeviceManager/DeviceMonitor.cpp @@ -56,48 +56,16 @@ QString DeviceMonitor::parseMonitorSize(const QString &sizeDescription, double & // 根据不同的正则表达式解析屏幕大小字符串 QString res = sizeDescription; -#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) - QRegExp re("^([\\d]*)x([\\d]*) mm$"); - if (re.exactMatch(sizeDescription)) { - qCDebug(appLog) << "Matched size description with format: ^([\\d]*)x([\\d]*) mm$"; - // 获取屏幕宽高 int - m_Width = re.cap(1).toInt(); - m_Height = re.cap(2).toInt(); - retSize = QSize(m_Width, m_Height); - - // 获取屏幕尺寸大小 inch - double width = m_Width / 2.54; - double height = m_Height / 2.54; - inch = std::sqrt(width * width + height * height) / 10.0; - res = QString::number(inch, 10, 1) + " " + translateStr("inch") + " ("; - res += sizeDescription; - res += ")"; - } - - re.setPattern("([0-9]\\d*)mm x ([0-9]\\d*)mm"); - if (re.exactMatch(sizeDescription)) { - qCDebug(appLog) << "Matched size description with format: ([0-9]\\d*)mm x ([0-9]\\d*)mm"; - // 获取屏幕宽高 int - m_Width = re.cap(1).toInt(); - m_Height = re.cap(2).toInt(); - retSize = QSize(m_Width, m_Height); - - double width = m_Width / 2.54; - double height = m_Height / 2.54; - inch = std::sqrt(width * width + height * height) / 10.0; - res = QString::number(inch, 10, 1) + " " + translateStr("inch") + " ("; - res += sizeDescription; - res += ")"; - } -#else QRegularExpression re("^([\\d]*)x([\\d]*) mm$"); QRegularExpressionMatch match = re.match(sizeDescription); if (match.hasMatch()) { qCDebug(appLog) << "Matched size description with format: ^([\\d]*)x([\\d]*) mm$"; + // 获取屏幕宽高 int m_Width = match.captured(1).toInt(); m_Height = match.captured(2).toInt(); retSize = QSize(m_Width, m_Height); + // 获取屏幕尺寸大小 inch double width = m_Width / 2.54; double height = m_Height / 2.54; inch = std::sqrt(width * width + height * height) / 10.0; @@ -110,6 +78,7 @@ QString DeviceMonitor::parseMonitorSize(const QString &sizeDescription, double & match = re.match(sizeDescription); if (match.hasMatch()) { qCDebug(appLog) << "Matched size description with format: ([0-9]\\d*)mm x ([0-9]\\d*)mm"; + // 获取屏幕宽高 int m_Width = match.captured(1).toInt(); m_Height = match.captured(2).toInt(); retSize = QSize(m_Width, m_Height); @@ -121,7 +90,6 @@ QString DeviceMonitor::parseMonitorSize(const QString &sizeDescription, double & res += sizeDescription; res += ")"; } -#endif qCDebug(appLog) << "Finished parsing monitor size. Result:" << res; return res; @@ -164,11 +132,7 @@ void DeviceMonitor::setInfoFromHwinfo(const QMap &mapInfo) caculateScreenRatio(); if (Common::isHwPlatform()){ -#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) - m_SupportResolution.replace(QRegExp(", $"), ""); -#else m_SupportResolution.replace(QRegularExpression(", $"), ""); -#endif } qCDebug(appLog) << "Supported resolutions processed:" << m_SupportResolution; @@ -288,7 +252,7 @@ bool DeviceMonitor::setInfoFromXradr(const QString &main, const QString &edid, c // 设置当前分辨率 if (m_CurrentResolution.isEmpty()) { qCDebug(appLog) << "Current resolution is empty, extracting from main string"; - QRegularExpression reScreenSize(".*([0-9]{1,5}x[0-9]{1,5}).*"); + QRegularExpression reScreenSize(".*connected.*\\s([0-9]{1,5}x[0-9]{1,5})\\+.*"); QRegularExpressionMatch match = reScreenSize.match(main); if (match.hasMatch()) { qCDebug(appLog) << "Matched screen size from main string:" << match.captured(1); @@ -320,11 +284,7 @@ bool DeviceMonitor::setInfoFromXradr(const QString &main, const QString &edid, c m_SupportResolution.append(", "); } } -#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) - m_SupportResolution.remove(QRegExp(", $")); -#else m_SupportResolution.remove(QRegularExpression(", $")); -#endif } } qCDebug(appLog) << "Interface already processed, returning false"; @@ -494,7 +454,7 @@ bool DeviceMonitor::setMainInfoFromXrandr(const QString &info, const QString &ra } // 设置当前分辨率 - QRegularExpression reScreenSize(".*([0-9]{1,5}x[0-9]{1,5}).*"); + QRegularExpression reScreenSize(".*connected.*\\s([0-9]{1,5}x[0-9]{1,5})\\+.*"); match = reScreenSize.match(info); if (match.hasMatch()) { qCDebug(appLog) << "Found screen size in xrandr info:" << match.captured(1); @@ -516,9 +476,9 @@ bool DeviceMonitor::setMainInfoFromXrandr(const QString &info, const QString &ra m_RefreshRate = QString("%1").arg(curRate); } if (Common::specialComType == 5 || Common::specialComType == 6) { - m_CurrentResolution = QString("%1").arg(QT_REGEXP_CAPTURE(reScreenSize, 1, info)).replace("x", "×", Qt::CaseInsensitive); + m_CurrentResolution = QString("%1").arg(match.captured(1)).replace("x", "×", Qt::CaseInsensitive); } else { - m_CurrentResolution = QString("%1 @%2").arg(QT_REGEXP_CAPTURE(reScreenSize, 1, info)).arg(curRate).replace("x", "×", Qt::CaseInsensitive); + m_CurrentResolution = QString("%1 @%2").arg(match.captured(1)).arg(curRate).replace("x", "×", Qt::CaseInsensitive); } } else { qCDebug(appLog) << "Rate is empty, setting current resolution without rate"; diff --git a/deepin-devicemanager/src/DeviceManager/DeviceStorage.cpp b/deepin-devicemanager/src/DeviceManager/DeviceStorage.cpp index dd6fb2fc..feb22abd 100644 --- a/deepin-devicemanager/src/DeviceManager/DeviceStorage.cpp +++ b/deepin-devicemanager/src/DeviceManager/DeviceStorage.cpp @@ -5,6 +5,7 @@ // 项目自身文件 #include "DeviceStorage.h" #include "commonfunction.h" +#include "commondefine.h" #include #include @@ -281,16 +282,13 @@ QString DeviceStorage::getSerialID(QString &strDeviceLink) qCDebug(appLog) << "DeviceStorage::getSerialID, device link contains platform"; // /devices/platform/f8300000.ufs/host0/target0:0:0/0:0:0:3 // /proc/bootdevice/name:f8300000.ufs - QRegularExpression reg(".*platform/([^/]+)/.*"); - QString strName = ""; - QString strBootdeviceName = ""; - if (reg.match(strDeviceLink).hasMatch()) { -#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) - strName = reg.cap(1); // Qt 5 -#else - strName = reg.match(strDeviceLink).captured(1); // Qt 6 -#endif - } + QRegularExpression reg(".*platform/([^/]+)/.*"); + QString strName = ""; + QString strBootdeviceName = ""; + QRegularExpressionMatch match = reg.match(strDeviceLink); + if (match.hasMatch()) { + strName = match.captured(1); + } if (!strName.isEmpty()) { //取到设备名称再去读文件,因为读文件开销大。 qCDebug(appLog) << "DeviceStorage::getSerialID, strName is not empty"; QString Path = "/proc/bootdevice/name"; @@ -571,18 +569,12 @@ QString DeviceStorage::compareSize(const QString &size1, const QString &size2) int num1 = 0; int num2 = 0; QRegularExpression reg(".*\\[(\\d+\\.?\\d+).*\\]"); - if (reg.match(size1).hasMatch()) -#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) - num1 = reg.cap(1).toInt(); // Qt 5 使用 cap -#else - num1 = reg.match(size1).captured(1).toInt(); // Qt 6 使用 captured -#endif - if (reg.match(size2).hasMatch()) -#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) - num2 = reg.cap(1).toInt(); // Qt 5 使用 cap -#else - num2 = reg.match(size2).captured(1).toInt(); // Qt 6 使用 captured -#endif + QRegularExpressionMatch match1 = reg.match(size1); + if (match1.hasMatch()) + num1 = match1.captured(1).toInt(); + QRegularExpressionMatch match2 = reg.match(size2); + if (match2.hasMatch()) + num2 = match2.captured(1).toInt(); // 返回较大值 if ((num1 - num2) > FLT_EPSILON * fmaxf(fabsf(num1), fabsf(num2))) { @@ -797,23 +789,17 @@ void DeviceStorage::getInfoFromsmartctl(const QMap &mapInfo) if (capacity != "") { qCDebug(appLog) << "DeviceStorage::getInfoFromsmartctl, capacity is not empty"; QRegularExpression reg(".*\\[(.*)\\]$"); - if (reg.match(capacity).hasMatch()) -#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) - m_Size = reg.cap(1); // Qt 5 使用 cap -#else - m_Size = reg.match(capacity).captured(1); // Qt 6 使用 captured -#endif + QRegularExpressionMatch sizeMatch = reg.match(capacity); + if (sizeMatch.hasMatch()) + m_Size = sizeMatch.captured(1); capacity.replace(",","").replace(" ",""); QRegularExpression re("(\\d+)bytes*"); //取值格式如: User Capacity: 1,000,204,886,016 bytes [1.00 TB] Total NVM Capacity: 256,060,514,304 [256 GB] int pos = re.match(capacity).capturedStart(); if (pos != -1) { qCDebug(appLog) << "DeviceStorage::getInfoFromsmartctl, capacity has match"; -#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) - QString byteSize = re.cap(1); // Qt 5 使用 cap -#else - QString byteSize = re.match(capacity).captured(1); // Qt 6 使用 captured -#endif + QRegularExpressionMatch byteMatch = re.match(capacity); + QString byteSize = byteMatch.captured(1); bool isValue = false; quint64 value = byteSize.trimmed().toULongLong(&isValue); if (value > 0 && isValue) diff --git a/deepin-devicemanager/src/Tool/ThreadExecXrandr.cpp b/deepin-devicemanager/src/Tool/ThreadExecXrandr.cpp index f7234ca6..6a4b50e9 100644 --- a/deepin-devicemanager/src/Tool/ThreadExecXrandr.cpp +++ b/deepin-devicemanager/src/Tool/ThreadExecXrandr.cpp @@ -189,7 +189,7 @@ void ThreadExecXrandr::loadXrandrVerboseInfo(QList> &lstM if ((*it).contains("*current")) { if ((it += 2) >= lines.end()) return; - QRegularExpression regRate(".*([0-9]{1,5}\\.[0-9]{1,5}Hz).*"); + QRegularExpression regRate(".*clock\\s+([0-9]{1,5}\\.[0-9]{1,5}Hz).*"); QRegularExpressionMatch rateMatch = regRate.match(*it); if (rateMatch.hasMatch()) { last.insert("rate", rateMatch.captured(1)); diff --git a/deepin-devicemanager/src/Widget/DetailTreeView.cpp b/deepin-devicemanager/src/Widget/DetailTreeView.cpp index 00f10d93..12bffa60 100644 --- a/deepin-devicemanager/src/Widget/DetailTreeView.cpp +++ b/deepin-devicemanager/src/Widget/DetailTreeView.cpp @@ -51,7 +51,6 @@ BtnWidget::BtnWidget() void BtnWidget::enterEvent(QEvent *event) { qCDebug(appLog) << "Mouse entered button widget"; -{ emit enter(); return DWidget::enterEvent(event); } diff --git a/deepin-devicemanager/src/Widget/DriverListView.cpp b/deepin-devicemanager/src/Widget/DriverListView.cpp index 60866634..6f5f4205 100644 --- a/deepin-devicemanager/src/Widget/DriverListView.cpp +++ b/deepin-devicemanager/src/Widget/DriverListView.cpp @@ -16,6 +16,10 @@ #include #include +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) +#include +#endif + using namespace DDLog; DriverListView::DriverListView(QWidget *parent) : DTreeView(parent) @@ -111,7 +115,7 @@ void DriverListView::drawRow(QPainter *painter, const QStyleOptionViewItem &opti QBrush background; if (!(index.row() & 1)) { #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) - auto dpa = DGuiApplicationHelper::instance()->palette(this); + auto dpa = DApplicationHelper::instance()->palette(this); background = dpa.color(DPalette::ItemBackground); #else // 当Qt版本为6.0或更高时,直接使用palette.color(cg, DPalette::Base)来获取背景颜 diff --git a/deepin-devicemanager/src/commondefine.h b/deepin-devicemanager/src/commondefine.h index 6e4c9e8e..eff6112b 100644 --- a/deepin-devicemanager/src/commondefine.h +++ b/deepin-devicemanager/src/commondefine.h @@ -33,18 +33,3 @@ const QString DEVICEINFO_PATH = "/tmp/device-info"; #else #define QT_SKIP_EMPTY_PARTS Qt::SkipEmptyParts #endif - -// Regular expression compatibility macros for Qt5/Qt6 -#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) -// Qt5 uses QRegExp -#define QT_REGEXP QRegExp -#define QT_REGEXP_MATCH(pattern, string) pattern.exactMatch(string) -#define QT_REGEXP_CAPTURE(pattern, index) pattern.cap(index) -#define QT_REGEXP_INDEX_IN(pattern, string) pattern.indexIn(string) -#else -// Qt6 uses QRegularExpression -#define QT_REGEXP QRegularExpression -#define QT_REGEXP_MATCH(pattern, string) pattern.match(string).hasMatch() -#define QT_REGEXP_CAPTURE(pattern, index, string) pattern.match(string).captured(index) -#define QT_REGEXP_INDEX_IN(pattern, string) pattern.match(string).hasMatch() ? 0 : -1 -#endif