Skip to content

Commit 0f67b44

Browse files
committed
refactor: move QML registration to factory initialization
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. 验证工厂初始化时机不影响模块加载
1 parent 1cf9591 commit 0f67b44

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

dcc-network/operation/dccnetwork.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2024 - 2027 UnionTech Software Technology Co., Ltd.
1+
// SPDX-FileCopyrightText: 2024 - 2026 UnionTech Software Technology Co., Ltd.
22
//
33
// SPDX-License-Identifier: GPL-3.0-or-later
44
#include "dccnetwork.h"
@@ -26,10 +26,6 @@ DccNetwork::DccNetwork(QObject *parent)
2626
: QObject(parent)
2727
, m_manager(nullptr)
2828
{
29-
qRegisterMetaType<QList<QVariantMap>>("NMVariantMapList");
30-
qmlRegisterType<NetType>("org.deepin.dcc.network", 1, 0, "NetType");
31-
qmlRegisterType<NetItemModel>("org.deepin.dcc.network", 1, 0, "NetItemModel");
32-
qmlRegisterType<NetManager>("org.deepin.dcc.network", 1, 0, "NetManager");
3329
QMetaObject::invokeMethod(this, "init", Qt::QueuedConnection);
3430
}
3531

@@ -202,6 +198,12 @@ void DccNetwork::init()
202198
Q_EMIT rootChanged();
203199
}
204200
DCC_FACTORY_CLASS(DccNetwork)
201+
DCC_FACTORY_INITIALIZE([]() {
202+
qRegisterMetaType<QList<QVariantMap>>("NMVariantMapList");
203+
qmlRegisterType<NetType>("org.deepin.dcc.network", 1, 0, "NetType");
204+
qmlRegisterType<NetItemModel>("org.deepin.dcc.network", 1, 0, "NetItemModel");
205+
qmlRegisterType<NetManager>("org.deepin.dcc.network", 1, 0, "NetManager");
206+
})
205207
} // namespace network
206208
} // namespace dde
207209

0 commit comments

Comments
 (0)