QAxAggregated Class
QAxAggregated 类是一个抽象基类,用于实现其他 COM 接口。更多
头文件: | #include <QAxAggregated> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS AxServer) target_link_libraries(mytarget PRIVATE Qt6::AxServer) |
qmake: | QT += axserver |
公共函数
virtual long | queryInterface(const QUuid &iid, void **iface) = 0 |
保护函数
virtual | ~QAxAggregated() |
IUnknown * | controllingUnknown() const |
QObject * | object() const |
QWidget * | widget() const |
详细说明
创建 QAxAggregated 的子类并重新实现queryInterface() 以支持其他 COM 接口。从这些 COM 接口使用多重继承。通过将对QueryInterface()
、AddRef()
和Release()
的调用委托给controllingUnknown() 提供的接口,实现这些 COM 接口的 IUnknown 接口。
如果需要调用实现 ActiveX 控件的QWidget ,请使用widget() 方法。您不得将该指针存储在子类中(除非您使用QPointer ),因为QWidget 可随时被 ActiveQt 框架销毁。
另请参阅 QAxBindable,QAxFactory, 以及 Active Qt.
成员函数文档
[virtual constexpr noexcept protected]
QAxAggregated::~QAxAggregated()
Qt 会在内部调用析构函数。
[protected]
IUnknown *QAxAggregated::controllingUnknown() const
返回 ActiveX 控件的IUnknown
接口。在QAxAggregated 子类中实现IUnknown
接口,将对QueryInterface()
、AddRef()
和Release()
的调用委托给该函数提供的接口。
HRESULT AxImpl::QueryInterface(REFIID iid, void **iface) { return controllingUnknown()->QueryInterface(iid, iface); } ulong AxImpl::AddRef() { return controllingUnknown()->AddRef(); } ulong AxImpl::Release() { return controllingUnknown()->Release(); }
您可以在子类的类声明中使用QAXAGG_IUNKNOWN
宏来代替手动声明和实现这三个函数。
[protected]
QObject *QAxAggregated::object() const
返回指向实现 COM 对象的QObject 子类的指针。此函数可能返回 0。
[pure virtual]
long QAxAggregated::queryInterface(const QUuid &iid, void **iface)
重新实现此纯虚拟函数以支持其他 COM 接口。设置iface 的值指向此对象,以支持接口iid 。请注意,必须将this
指针转换为相应的超类。
long AxImpl::queryInterface(const QUuid &iid, void **iface) { *iface = 0; if (iid == IID_ISomeCOMInterface) *iface = (ISomeCOMInterface*)this; else return E_NOINTERFACE; AddRef(); return S_OK; }
返回标准 COM 结果S_OK
(支持接口)或E_NOINTERFACE
(不支持请求的接口)。
警告: 即使您必须实现IUnknown
接口,如果您实现了任何 COM 接口,也不得在您的 queryInterface() 实现中支持IUnknown
接口。
[protected]
QWidget *QAxAggregated::widget() const
返回指向实现 ActiveX 控件的QWidget 子类的指针。此函数可能返回 0。
© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.