QtCanpool 3.3.0
载入中...
搜索中...
未找到
QxPlugin::QxPlugin类 参考abstract

Base class of every QtCanpool plugin. 更多...

#include <qxplugin/qxplugin.h>

类 QxPlugin::QxPlugin 继承关系图:

Public 成员函数

 QxPlugin (QObject *parent=Q_NULLPTR)
 
 ~QxPlugin () override
 
virtual bool initialize (QxPluginContext *context, QString *errorString)=0
 Called after every required dependency has been initialized.
 
virtual void extensionsInitialized ()
 Called once every plugin is initialized: the place to finish setup that had to wait for the whole set.
 
virtual void shutdown ()
 Called in reverse initialization order on shutdown.
 
virtual int interfaceVersion () const
 The plugin interface version this build targets.
 
QxPluginContext * context () const
 The host context handed to initialize(); null before that call.
 

Protected 属性

QxPluginContext * m_context = Q_NULLPTR
 Set by the manager before initialize(); also reachable through context().
 

友元

class QxPluginManager
 QxPluginManager sets m_context before initialize(); nothing else should.
 

详细描述

Base class of every QtCanpool plugin.

A plugin is a QObject whose concrete subclass carries Q_PLUGIN_METADATA(IID QX_PLUGIN_IID FILE "<name>.json") and is loaded by QxPluginManager. The host calls initialize() once every required dependency is up, hands it a QxPluginContext, and expects false (with a reason) when the plugin cannot start; extensionsInitialized() runs once the whole set is up; shutdown() runs in reverse when the host goes down.

QxPluginContext is a plugin's only handle: host capabilities are reached through it and nothing else. A plugin has no handle to the manager and none to its peers as objects it may simply drive. Plugins program against QxPluginContext, never against the window class, so renaming the host - a K14 concern - never reaches a single plugin.

That is a property of the runtime and not only of this comment: a static instance is owned through a private holder rather than parented to the manager, and a dynamic instance is owned by its QPluginLoader and has no parent, so no plugin can walk the object tree back to the manager and from there to its peers.

Two plugins still have to be able to cooperate, and the object pool on QxPluginContext is the whole of how: the providing side publishes what it offers, the wanting side looks it up by name or by type, and neither includes the other's header. What that replaces is a host that names both ends and connects them itself - a host that knows no module by name is only possible because the modules can meet without it.

class MyPlugin : public QxPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID QX_PLUGIN_IID FILE "myplugin.json")
public:
bool initialize(QxPluginContext *context, QString *errorString) override;
};
The thin surface a plugin programs against.
Copyright (C) 2026 maminjie canpool@163.com SPDX-License-Identifier: MulanPSL-2.0
#define QX_PLUGIN_IID

在文件 qxplugin.h 第 55 行定义.

构造及析构函数说明

◆ QxPlugin()

QxPlugin::QxPlugin::QxPlugin ( QObject *  parent = Q_NULLPTR)
explicit

在文件 qxplugin.cpp 第 9 行定义.

◆ ~QxPlugin()

QxPlugin::QxPlugin::~QxPlugin ( )
override

在文件 qxplugin.cpp 第 15 行定义.

成员函数说明

◆ context()

QxPluginContext * QxPlugin::QxPlugin::context ( ) const

The host context handed to initialize(); null before that call.

在文件 qxplugin.cpp 第 32 行定义.

◆ extensionsInitialized()

void QxPlugin::QxPlugin::extensionsInitialized ( )
virtual

Called once every plugin is initialized: the place to finish setup that had to wait for the whole set.

Peers are reachable here exactly as they are in initialize() - through the object pool on the context - and a plugin that offers something may prefer to publish it here, when it can be sure its own setup is complete. Empty by default.

The call runs in the order the plugins were initialized in. That is worth knowing if you care whether a plugin you depend on has reached this point yet; it is not a reverse-order guarantee of the kind Qt Creator promises.

在文件 qxplugin.cpp 第 19 行定义.

◆ initialize()

virtual bool QxPlugin::QxPlugin::initialize ( QxPluginContext *  context,
QString *  errorString 
)
pure virtual

Called after every required dependency has been initialized.

Take from context whatever the plugin needs and return false - filling errorString - when it cannot run. A false return removes the plugin and every plugin that depends on it from the run; the host keeps starting.

◆ interfaceVersion()

int QxPlugin::QxPlugin::interfaceVersion ( ) const
virtual

The plugin interface version this build targets.

The host refuses to call initialize() when it is below what the host requires, which is how a 5.0 interface change can be rejected cleanly. The first interface is 1.

在文件 qxplugin.cpp 第 27 行定义.

◆ shutdown()

void QxPlugin::QxPlugin::shutdown ( )
virtual

Called in reverse initialization order on shutdown.

Must not fail.

在文件 qxplugin.cpp 第 23 行定义.

友元及相关函数文档

◆ QxPluginManager

friend class QxPluginManager
friend

QxPluginManager sets m_context before initialize(); nothing else should.

在文件 qxplugin.h 第 59 行定义.

类成员变量说明

◆ m_context

QxPluginContext* QxPlugin::QxPlugin::m_context = Q_NULLPTR
protected

Set by the manager before initialize(); also reachable through context().

在文件 qxplugin.h 第 99 行定义.


该类的文档由以下文件生成: