Skip to content

Commit 3e3b932

Browse files
committed
fix: resolve compilation warnings and Qt6 compatibility issues
1. Replaced QScopedPointer with std::unique_ptr for better memory management and consistency 2. Added Qt6-specific includes (type_traits) for compatibility 3. Updated qAsConst to std::as_const for Qt6 compatibility 4. Fixed time handling in DRecentManager for Qt6 by using QTimeZone 5. Added missing memory header for smart pointers These changes address compiler warnings and ensure proper functionality across both Qt5 and Qt6 versions, while modernizing the codebase with standard C++ features. fix: 修复编译警告和Qt6兼容性问题 1. 使用std::unique_ptr替代QScopedPointer以获得更好的内存管理和一致性 2. 添加Qt6特定的头文件(type_traits)以保证兼容性 3. 将qAsConst更新为std::as_const以兼容Qt6 4. 在DRecentManager中修复Qt6的时间处理问题,使用QTimeZone 5. 添加缺失的memory头文件以支持智能指针 这些修改解决了编译器警告问题,并确保代码在Qt5和Qt6版本中都能正常工作,同 时使用标准C++特性使代码更现代化。
1 parent 97e66aa commit 3e3b932

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

src/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ find_package(ICU REQUIRED COMPONENTS uc)
2525
pkg_check_modules(uchardet REQUIRED uchardet)
2626
# end text encoding
2727

28+
# 为不包含实际QObject类的头文件跳过AutoMOC处理
29+
set_property(SOURCE ../include/base/dsingleton.h PROPERTY SKIP_AUTOMOC ON)
30+
if("${DTK_VERSION_MAJOR}" STREQUAL "6")
31+
set_property(SOURCE ../include/util/dthreadutils.h PROPERTY SKIP_AUTOMOC ON)
32+
endif()
33+
2834
# start base
2935
include(base/base.cmake)
3036
# end base

src/dconfig.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
#include <QLoggingCategory>
1919
#include <QCoreApplication>
2020
#include <unistd.h>
21+
#include <memory>
22+
#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
23+
#include <type_traits>
24+
#endif
2125

2226
// https://gitlabwh.uniontech.com/wuhan/se/deepin-specifications/-/issues/3
2327

@@ -173,13 +177,13 @@ class Q_DECL_HIDDEN FileBackend : public DConfigBackend
173177
if (owner->appId == NoAppId)
174178
return true;
175179

176-
QScopedPointer<DConfigFile> file(new DConfigFile(NoAppId, owner->name, owner->subpath));
180+
std::unique_ptr<DConfigFile> file(new DConfigFile(NoAppId, owner->name, owner->subpath));
177181
const bool canFallbackToGeneric = !file->meta()->metaPath(prefix).isEmpty();
178182
if (canFallbackToGeneric) {
179-
QScopedPointer<DConfigCache> cache(file->createUserCache(getuid()));
183+
std::unique_ptr<DConfigCache> cache(file->createUserCache(getuid()));
180184
if (file->load(prefix) && cache->load(prefix)) {
181-
genericConfigFile.reset(file.take());
182-
genericConfigCache.reset(cache.take());
185+
genericConfigFile.reset(file.release());
186+
genericConfigCache.reset(cache.release());
183187
}
184188
}
185189
return true;
@@ -370,7 +374,11 @@ class Q_DECL_HIDDEN DBusBackend : public DConfigBackend
370374
complexType >> list;
371375
QVariantList res;
372376
res.reserve(list.size());
377+
#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
378+
for (const auto &item : std::as_const(list)) {
379+
#else
373380
for (const auto &item : qAsConst(list)) {
381+
#endif
374382
res << decodeQDBusArgument(item);
375383
}
376384
return res;

src/util/drecentmanager.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <QUrl>
1414
#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
1515
#include <QStringConverter>
16+
#include <QTimeZone>
1617
#endif
1718

1819
DCORE_BEGIN_NAMESPACE
@@ -67,7 +68,11 @@ bool DRecentManager::addItem(const QString &uri, DRecentData &data)
6768
QFile file(RECENT_PATH);
6869
file.open(QIODevice::ReadWrite | QIODevice::Text);
6970

71+
#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
72+
QString dateTime = QDateTime::currentDateTime().toTimeZone(QTimeZone::UTC).toString(Qt::ISODate);
73+
#else
7074
QString dateTime = QDateTime::currentDateTime().toTimeSpec(Qt::OffsetFromUTC).toString(Qt::ISODate);
75+
#endif
7176
QDomDocument doc;
7277

7378
if (!doc.setContent(&file)) {

0 commit comments

Comments
 (0)