Skip to content

refactor: move QML registration to factory initialization#540

Open
18202781743 wants to merge 1 commit intolinuxdeepin:masterfrom
18202781743:flow
Open

refactor: move QML registration to factory initialization#540
18202781743 wants to merge 1 commit intolinuxdeepin:masterfrom
18202781743:flow

Conversation

@18202781743
Copy link
Copy Markdown
Contributor

@18202781743 18202781743 commented Apr 3, 2026

  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. 验证工厂初始化时机不影响模块加载

Summary by Sourcery

Move QML type and metatype registration for the network module from the DccNetwork constructor to the factory initialization phase to ensure proper initialization timing and threading.

Enhancements:

  • Register network-related QML types and the NMVariantMapList metatype during DCC factory initialization instead of in the DccNetwork object constructor.
  • Update the SPDX copyright year range in dccnetwork.cpp.

@deepin-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 18202781743

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai bot commented Apr 3, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Moves QML type and metatype registration for the DccNetwork module from the DccNetwork constructor to a DCC_FACTORY_INITIALIZE lambda to ensure registration occurs on the main thread during factory initialization, while keeping the runtime behavior of the QML-facing API unchanged.

Sequence diagram for QML registration moved to DCC_FACTORY_INITIALIZE

sequenceDiagram
    actor QmlEngine
    participant DccFactory
    participant MainThread
    participant WorkerThread
    participant DccNetwork

    QmlEngine->>DccFactory: load network module
    DccFactory->>MainThread: DCC_FACTORY_INITIALIZE lambda
    activate MainThread
    MainThread->>MainThread: qRegisterMetaType NMVariantMapList
    MainThread->>MainThread: qmlRegisterType NetType
    MainThread->>MainThread: qmlRegisterType NetItemModel
    MainThread->>MainThread: qmlRegisterType NetManager
    deactivate MainThread

    QmlEngine->>WorkerThread: request DccNetwork instance
    WorkerThread->>DccNetwork: constructor
    activate DccNetwork
    DccNetwork->>DccNetwork: QMetaObject::invokeMethod init (QueuedConnection)
    deactivate DccNetwork

    Note over QmlEngine,DccNetwork: QML types are already registered before any DccNetwork construction, even if constructed off the main thread
Loading

File-Level Changes

Change Details Files
Relocate QML and metatype registration from the DccNetwork constructor to factory initialization using DCC_FACTORY_INITIALIZE.
  • Removed qRegisterMetaType and qmlRegisterType calls from the DccNetwork constructor body to avoid running them from potentially non-main threads.
  • Added a DCC_FACTORY_INITIALIZE lambda that performs the same qRegisterMetaType and qmlRegisterType registrations during factory initialization, which is expected to run on the main thread.
  • Preserved the existing asynchronous initialization pattern of DccNetwork by keeping the QMetaObject::invokeMethod(..., Qt::QueuedConnection) call in the constructor.
  • Updated the SPDX copyright year range in the implementation file.
dcc-network/operation/dccnetwork.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • The SPDX-FileCopyrightText year range was changed from 2024 - 2027 to 2024 - 2026; please confirm whether this narrowing of the range is intentional and aligns with your licensing policy.
  • Now that QML registration is done in DCC_FACTORY_INITIALIZE, please double-check that this macro guarantees the lambda runs exactly once on the main thread so that repeated or concurrent factory initialization cannot lead to multiple QML registrations or threading issues.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The SPDX-FileCopyrightText year range was changed from `2024 - 2027` to `2024 - 2026`; please confirm whether this narrowing of the range is intentional and aligns with your licensing policy.
- Now that QML registration is done in `DCC_FACTORY_INITIALIZE`, please double-check that this macro guarantees the lambda runs exactly once on the main thread so that repeated or concurrent factory initialization cannot lead to multiple QML registrations or threading issues.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

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. 验证工厂初始化时机不影响模块加载
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants