本页内容

QAxAggregated Class

QAxAggregated 类是用于实现其他 COM 接口的抽象基类。更多内容...

头文件: #include <qaxaggregated.h>
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

受保护函数

QAxAggregated()
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 ),因为 ActiveQt 框架可能会随时销毁该QWidget 。

另请参阅 QAxBindable 、QAxFactory 以及 Active Qt。

成员函数文档

[constexpr noexcept protected default] QAxAggregated::QAxAggregated()

默认创建一个QAxAggregated 实例。

[virtual constexpr noexcept protected default] 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。

警告: 除非您使用的是QPointer ,否则请 勿存储返回的指针,因为QObject 可能会被ActiveQt在任何时候销毁。

[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 (表示不支持所请求的接口)。

警告:尽管在 实现任何 COM 接口时都 必须实现IUnknown 接口,但在 queryInterface() 的实现中,切勿支持IUnknown 接口。

[protected] QWidget *QAxAggregated::widget() const

返回指向实现 ActiveX 控件的QWidget 子类的指针。该函数可能会返回 0。

警告: 除非您使用的是QPointer ,否则切勿 存储该返回的指针,因为QWidget 可能会随时被ActiveQt销毁。

© 2026 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.