Frontend Development 17 min read

Componentization in the QianNiu PC Cross‑Platform Framework

The QianNiu PC cross‑platform framework adopts a COM‑style component architecture—defining interfaces, implementations, and MVP‑based UI modules, with automated code generation and lifecycle management—to achieve consistent Windows/macOS features, improve extensibility and reusability, lower development cost, and boost maintainability and efficiency.

DaTaobao Tech
DaTaobao Tech
DaTaobao Tech
Componentization in the QianNiu PC Cross‑Platform Framework

This article introduces the component‑based design of the QianNiu PC cross‑platform framework, describing the motivations, solution choices, encountered problems, and resolutions.

Background : Maintaining feature parity across Windows and macOS desktop clients incurs high cost and inconsistent user experience. A unified component framework is needed to address these challenges.

Why Componentization? Componentization provides excellent extensibility, reusability, flexibility, low impact of changes, and supports team collaboration.

Component Framework Overview : The framework offers component discovery, lifecycle management, inter‑component communication, and common base capabilities. Components follow a prg::com model similar to COM, with interfaces (IxxxService) and implementations (CxxxService).

Example of defining a component:

// Define a prg::com component
class IxxxService;
DEFINE_IID(IxxxService, "{4E6A382D-1FDA-49C6-8521-E284DA7B71CC}")
DEFINE_CLSID(xxxService, "{D1A52645-7587-4885-ABFD-323BA62905F5}")

// Create the component instance
scoped_refptr<IxxxService> spInterface;
prg::PrgCOMCreateInstance(c_uuidof(xxxService), spInterface);

// Implementation (hidden from external)
class CxxxService : public prg::CPrgCOMRootObject<prg::CCOMThreadSafeRefPolicy>, public IxxxService {
public:
  DECLARE_PRGCOM_RUNTIME(CxxxService, c_uuidof(xxxService), "xxxService", "xxxService", prg::GetDependsCLSID())
  BEGIN_PRGCOM_MAP(CxxxService)
    PRGCOM_INTERFACE_ENTRY(IxxxService)
  END_PRGCOM_MAP()
};
IMPLEMENT_PRGCOM_RUNTIME(CxxxService);

The framework scans DLLs at build time, generates XML configuration, registers CLSIDs, and enables creation of component instances without direct dependencies.

UI Component Standards : UI components follow an MVP pattern. Each UI consists of a Service (component), Presenter (logic), and View (rendering). The Presenter defines a delegate interface implemented by the View, allowing the logic to be unit‑tested via mock delegates.

Lifecycle management handles the fact that UI objects are owned by the UI framework (e.g., Qt) while the component lifecycle is managed by the prg kernel. Mechanisms are provided to notify components when UI objects are destroyed.

Code Generation : Because component development involves many boilerplate files (interface, implementation, presenter, view, etc.), a code‑generation tool creates these files from templates, reducing effort and ensuring consistency.

Results : The componentization solution has been deployed in QianNiu and AliWangWang, achieving cross‑platform consistency, reduced development cost, improved maintainability, and higher development efficiency.

software architecturecross-platformUIC++componentizationframework
DaTaobao Tech
Written by

DaTaobao Tech

Official account of DaTaobao Technology

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.