Skip to content

Commit 135014f

Browse files
committed
fix: resolve Qt6 compilation warnings and deprecations
1. Added conditional compilation for Qt5/Qt6 compatibility 2. Replaced deprecated qAsConst with std::as_const for Qt6 3. Added D_IGNORE_DEPRECATIONS flag to suppress deprecation warnings 4. Fixed static_assert removal in dbackdropnode.cpp 5. Added missing Q_UNUSED macro in dquickimageprovider.cpp 6. Cleaned up initialization syntax in dquickwindow_p.h 7. Fixed platform check from IsTreelandPlatform to IsWaylandPlatform 8. Improved memory management in AppLoaderSimulator destructor Influence: 1. Verify application builds successfully with both Qt5 and Qt6 2. Test high DPI functionality on both Qt versions 3. Validate blur effects and window management features 4. Check all QML components render correctly 5. Test palette and color selector functionality 6. Verify shadow provider image generation 7. Test settings container and group visibility fix: 解决Qt6编译警告和废弃API问题 1. 添加Qt5/Qt6兼容性条件编译 2. 将废弃的qAsConst替换为std::as_const(Qt6) 3. 添加D_IGNORE_DEPRECATIONS标志抑制废弃API警告 4. 修复dbackdropnode.cpp中移除的static_assert 5. 在dquickimageprovider.cpp中添加缺失的Q_UNUSED宏 6. 清理dquickwindow_p.h中的初始化语法 7. 将平台检查从IsTreelandPlatform修正为IsWaylandPlatform 8. 改进AppLoaderSimulator析构函数的内存管理 Influence: 1. 验证应用在Qt5和Qt6下都能成功构建 2. 测试两个Qt版本下的高DPI功能 3. 验证模糊效果和窗口管理功能 4. 检查所有QML组件是否正确渲染 5. 测试调色板和颜色选择器功能 6. 验证阴影提供者图像生成 7. 测试设置容器和组可见性
1 parent baff951 commit 135014f

13 files changed

Lines changed: 103 additions & 18 deletions

examples/exhibition/main.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ class Object : public QObject {
6161

6262
int main(int argc, char **argv)
6363
{
64+
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
6465
QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
66+
#endif
6567

6668
QGuiApplication app(argc, argv);
6769
app.setOrganizationName("deepin");

examples/qml-inspect/main.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99

1010
int main(int argc, char *argv[])
1111
{
12+
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
1213
QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
14+
#endif
1315

1416
QGuiApplication app(argc, argv);
1517
app.setOrganizationName("deepin");

qt6/src/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ qt_add_qml_module(${LIB_NAME}
2121

2222
dtk_extend_target(${LIB_NAME} EnableCov ${ENABLE_COV})
2323
dtk_extend_target(${PLUGIN_NAME} EnableCov ${ENABLE_COV})
24+
target_compile_definitions(${LIB_NAME} PRIVATE
25+
D_IGNORE_DEPRECATIONS
26+
)
2427

2528
qt_add_translations(${LIB_NAME}
2629
TS_FILES ${TS_FILES}

src/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ add_library(${LIB_NAME} SHARED
1717
)
1818

1919
dtk_extend_target(${LIB_NAME} EnableCov ${ENABLE_COV})
20+
target_compile_definitions(${LIB_NAME} PRIVATE
21+
D_IGNORE_DEPRECATIONS
22+
)
2023

2124
set_target_properties(${LIB_NAME} PROPERTIES
2225
VERSION ${CMAKE_PROJECT_VERSION}

src/dapploader.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Q_LOGGING_CATEGORY(appLoaderLog, "dtk.quick.apploader");
4040
static const QQuickItemPrivate::ChangeTypes changedTypes = QQuickItemPrivate::Geometry;
4141
DAppLoader *DAppLoader::self = nullptr;
4242

43-
static inline const bool heightValid(QQuickItemPrivate *item)
43+
static inline bool heightValid(QQuickItemPrivate *item)
4444
{
4545
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
4646
return item->heightValid;
@@ -246,7 +246,11 @@ bool DAppLoaderPrivate::createObjects(const char *propertyName)
246246
void DAppLoaderPrivate::createChildComponents()
247247
{
248248
auto components = appRootItem->findChildren<QQmlComponent *>(QStringLiteral(""), Qt::FindDirectChildrenOnly);
249+
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
250+
for (auto childCom : std::as_const(components)) {
251+
#else
249252
for (auto childCom : qAsConst(components)) {
253+
#endif
250254
QObject::connect(childCom, SIGNAL(progressChanged(qreal)), q_func(), SLOT(_q_onComponentProgressChanged()));
251255
auto asyn = appRootItem->asynchronous() ? DQmlComponentIncubator::Asynchronous : DQmlComponentIncubator::AsynchronousIfNested;
252256
DQmlComponentIncubator *incubator = new DQmlComponentIncubator(childCom, this, asyn);
@@ -436,7 +440,11 @@ void DAppLoaderPrivate::_q_onComponentProgressChanged()
436440
{
437441
qreal progress = 0;
438442
auto components = appRootItem->findChildren<QQmlComponent *>();
443+
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
444+
for (auto childCom : std::as_const(components) {
445+
#else
439446
for (auto childCom : qAsConst(components)) {
447+
#endif
440448
progress += childCom->progress();
441449
}
442450

src/dquickwindow.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <private/qquickwindow_p.h>
1616

1717
#include <QPlatformSurfaceEvent>
18+
#include <qglobal.h>
1819

1920
DQUICK_BEGIN_NAMESPACE
2021

@@ -226,7 +227,11 @@ void DQuickWindowAttachedPrivate::_q_updateBlurAreaForWindow()
226227
QList<QPainterPath> blurPathList;
227228
QVector<DPlatformHandle::WMBlurArea> blurAreaList;
228229

230+
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
231+
for (const DQuickBehindWindowBlur *blur : std::as_const(blurList)) {
232+
#else
229233
for (const DQuickBehindWindowBlur *blur : qAsConst(blurList)) {
234+
#endif
230235
if (!blur->d_func()->isValidBlur())
231236
continue;
232237

@@ -244,7 +249,11 @@ void DQuickWindowAttachedPrivate::_q_updateBlurAreaForWindow()
244249
blurSuc = q->setWindowBlurAreaByWM(blurAreaList);
245250
} else {
246251
// convert to QPainterPath
252+
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
253+
for (const DPlatformHandle::WMBlurArea &area : std::as_const(blurAreaList)) {
254+
#else
247255
for (const DPlatformHandle::WMBlurArea &area : qAsConst(blurAreaList)) {
256+
#endif
248257
QPainterPath path;
249258
path.addRoundedRect(area.x, area.y, area.width, area.height, area.xRadius, area.yRaduis);
250259
blurPathList << path;
@@ -343,7 +352,7 @@ bool DQuickWindowAttached::isEnabled() const
343352
{
344353
D_DC(DQuickWindowAttached);
345354
return d->handle && (DPlatformHandle::isEnabledDXcb(window())
346-
|| DGuiApplicationHelper::testAttribute(DGuiApplicationHelper::IsTreelandPlatform));
355+
|| DGuiApplicationHelper::testAttribute(DGuiApplicationHelper::IsWaylandPlatform));
347356
}
348357

349358
/*!

src/private/dbackdropnode.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ class Q_DECL_HIDDEN DataManager : public DataManagerBase
145145
}
146146

147147
static DataManagerPointer<Derive> resolve(const DataManagerPointer<Derive> &other, QQuickWindow *owner) {
148-
static_assert(&Derive::metaObject);
149148
Q_ASSERT(owner);
150149
if (other && other->owner() == owner)
151150
return other;
@@ -828,7 +827,6 @@ class Q_DECL_HIDDEN RhiNode : public DBackdropNode {
828827
texture->data->pixelSize().height() / float(m_rect.height() * devicePixelRatio)});
829828
rhi->render(renderData->rt.get());
830829
} else {
831-
auto rhi = this->rhi->rhi();
832830
QPointF sourcePos = renderMatrix.map(m_rect.topLeft()) * devicePixelRatio;
833831

834832
if (ct) {

src/private/dquickcontrolpalette.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,11 @@ void DQuickControlColorSelector::findAndSetControlParent()
344344
{
345345
QQuickItem *parentItem = qobject_cast<QQuickItem*>(parent());
346346
Q_ASSERT(parentItem);
347+
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
347348
for (const QMetaObject::Connection &conn : qAsConst(m_itemParentChangeConnections)) {
349+
#else
350+
for (const QMetaObject::Connection &conn : std::as_const(m_itemParentChangeConnections)) {
351+
#endif
348352
disconnect(conn);
349353
}
350354
m_itemParentChangeConnections.clear();
@@ -1028,7 +1032,11 @@ void DQuickControlColorSelector::recvPaletteColorChanged()
10281032
auto palette = qobject_cast<DQuickControlPalette*>(sender());
10291033
Q_ASSERT(palette);
10301034
// Maybe the multiple properties is use a same palette.
1035+
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
1036+
for (const auto &i : std::as_const(m_palettes)) {
1037+
#else
10311038
for (const auto &i : qAsConst(m_palettes)) {
1039+
#endif
10321040
if (i.second != palette)
10331041
continue;
10341042
updatePropertyFromName(i.first, palette);
@@ -1040,7 +1048,11 @@ void DQuickControlColorSelector::onPaletteDestroyed()
10401048
auto palette = sender();
10411049
Q_ASSERT(palette);
10421050
// Maybe the multiple properties is use a same palette.
1051+
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
1052+
for (const auto &i : std::as_const(m_palettes)) {
1053+
#else
10431054
for (const auto &i : qAsConst(m_palettes)) {
1055+
#endif
10441056
if (i.second != palette)
10451057
continue;
10461058
setPalette(i.first, nullptr);

src/private/dquickimageprovider.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ static QPainterPath roundedRectPath(const QRectF &rect, const DQuickShadowProvid
432432

433433
QImage DQuickShadowProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize)
434434
{
435+
Q_UNUSED(requestedSize)
435436
ShadowConfig config;
436437
QColor color;
437438
qreal xOffset;

src/private/dquickwaterprogressattribute_p.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ class WaterPopAttribute : public QObject
5656

5757
qreal sizeRatio() const;
5858

59-
inline qreal yOffset() const;
60-
inline void setYOffset(qreal offset);
59+
qreal yOffset() const;
60+
void setYOffset(qreal offset);
6161

6262
Q_SIGNALS:
6363
void xSpeedChanged();

0 commit comments

Comments
 (0)