From 051fb905da47a80932f22324555b121d1d8c10ea Mon Sep 17 00:00:00 2001 From: yeshanshan Date: Fri, 3 Apr 2026 18:40:17 +0800 Subject: [PATCH] refactor: move QML registration to factory initialization MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. Moved QML type registrations from DccNetwork constructor to DCC_FACTORY_INITIALIZE lambda 2. This ensures QML registrations happen in the main thread during factory initialization 3. Previously registrations occurred in constructor which could be called from non-main threads 4. Using DCC_FACTORY_INITIALIZE ensures proper timing for factory initialization Influence: 1. Verify network module QML components are properly registered and accessible 2. Test network module functionality in QML applications 3. Ensure no threading issues during module initialization 4. Verify factory initialization timing doesn't affect module loading refactor: 将QML注册移动到工厂初始化中 1. 将QML类型注册从DccNetwork构造函数移动到DCC_FACTORY_INITIALIZE lambda 表达式 2. 确保QML注册在主线程中执行,在工厂初始化期间完成 3. 之前注册在构造函数中进行,可能从非主线程调用 4. 使用DCC_FACTORY_INITIALIZE确保工厂初始化的正确时机 Influence: 1. 验证网络模块QML组件是否正确注册并可访问 2. 测试QML应用程序中的网络模块功能 3. 确保模块初始化期间没有线程问题 4. 验证工厂初始化时机不影响模块加载 --- dcc-network/operation/dccnetwork.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/dcc-network/operation/dccnetwork.cpp b/dcc-network/operation/dccnetwork.cpp index 644a1cf3..981e9a0a 100644 --- a/dcc-network/operation/dccnetwork.cpp +++ b/dcc-network/operation/dccnetwork.cpp @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2024 - 2027 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2024 - 2026 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: GPL-3.0-or-later #include "dccnetwork.h" @@ -26,10 +26,6 @@ DccNetwork::DccNetwork(QObject *parent) : QObject(parent) , m_manager(nullptr) { - qRegisterMetaType>("NMVariantMapList"); - qmlRegisterType("org.deepin.dcc.network", 1, 0, "NetType"); - qmlRegisterType("org.deepin.dcc.network", 1, 0, "NetItemModel"); - qmlRegisterType("org.deepin.dcc.network", 1, 0, "NetManager"); QMetaObject::invokeMethod(this, "init", Qt::QueuedConnection); } @@ -202,6 +198,12 @@ void DccNetwork::init() Q_EMIT rootChanged(); } DCC_FACTORY_CLASS(DccNetwork) +DCC_FACTORY_INITIALIZED([]() { + qRegisterMetaType>("NMVariantMapList"); + qmlRegisterType("org.deepin.dcc.network", 1, 0, "NetType"); + qmlRegisterType("org.deepin.dcc.network", 1, 0, "NetItemModel"); + qmlRegisterType("org.deepin.dcc.network", 1, 0, "NetManager"); +}) } // namespace network } // namespace dde