QAxBindable Class
QAxBindable 类提供了QWidget 与 ActiveX 客户端之间的接口。更多
头文件: | #include <QAxBindable> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS AxServer) target_link_libraries(mytarget PRIVATE Qt6::AxServer) |
qmake: | QT += axserver |
公共函数
QAxBindable() | |
virtual | ~QAxBindable() |
virtual QAxAggregated * | createAggregate() |
virtual bool | readData(QIODevice *source, const QString &format) |
void | reportError(int code, const QString &src, const QString &desc, const QString &context = QString()) |
virtual bool | writeData(QIODevice *sink) |
保护函数
IUnknown * | clientSite() const |
void | propertyChanged(const char *property) |
bool | requestPropertyChange(const char *property) |
详细说明
通过该类提供的函数,ActiveX 控件可将属性更改传达给客户端程序。从QWidget (直接或间接)和该类继承您的控件类,即可访问该类的函数。元对象编译器要求您首先从QWidget 继承。
class MyActiveX : public QWidget, public QAxBindable { Q_OBJECT Q_PROPERTY(int value READ value WRITE setValue) public: MyActiveX(QWidget *parent = 0); ... int value() const; void setValue(int); };
在实现属性写入函数时,使用requestPropertyChange() 从 ActiveX 客户端程序获取更改该属性的权限。当属性发生变化时,调用propertyChanged() 通知 ActiveX 客户端程序。如果控件发生致命错误,则使用静态reportError() 函数通知客户端。
使用clientSite() 返回的接口调用 ActiveX 客户端。要在 ActiveX 控件中实现其他 COM 接口,请重新实现createAggregate() 以返回QAxAggregated 子类的新对象。
另请参阅 QAxAggregated,QAxFactory, 和ActiveQt 框架。
成员函数文档
QAxBindable::QAxBindable()
构造一个空的 QAxBindable 对象。
[virtual noexcept]
QAxBindable::~QAxBindable()
销毁QAxBindable 对象。
[protected]
IUnknown *QAxBindable::clientSite() const
返回指向此 ActiveX 对象客户站点接口的指针,如果未设置客户站点,则返回空值。
在返回的接口上调用QueryInterface()
,以获得要调用的接口。
[virtual]
QAxAggregated *QAxBindable::createAggregate()
当您想在 ActiveX 控件中实现其他 COM 接口,或想提供 COM 接口的替代实现时,请重新实现该函数。返回QAxAggregated 子类的新对象。
默认实现返回空指针。
[protected]
void QAxBindable::propertyChanged(const char *property)
调用此函数可通知托管此 ActiveX 控件的客户端,属性property 已更改。
该函数通常在属性的写入函数结束时调用。
另请参阅 requestPropertyChange()。
[virtual]
bool QAxBindable::readData(QIODevice *source, const QString &format)
如果 COM 对象支持 MIME 类型,则调用此函数从format 中的数据source 初始化 COM 对象。在从source 读取数据之前,必须先打开 供读取。
返回 true 表示成功。如果函数返回 false,则 ActiveQt 将通过元对象系统设置属性来处理数据。
如果重新实现此函数,还必须实现writeData()。默认实现什么也不做,返回 false。
警告: 嵌入 HTML 的 ActiveX 控件可以使用object
标签的type
和data
属性读取数据,或使用param
标签列表初始化属性。如果使用param
标记,Internet Explorer 将忽略data
属性,也不会调用 readData。
另请参阅 writeData()。
void QAxBindable::reportError(int code, const QString &src, const QString &desc, const QString &context = QString())
code 是控件定义的错误代码。desc 是供应用程序用户阅读的错误描述。src 是错误源的名称,通常是 ActiveX 服务器名称。context 可以是包含更多错误信息的帮助文件的位置。如果context 以括号内的数字结尾,例如 [12],则该数字将被解释为帮助文件中的上下文 ID。
[protected]
bool QAxBindable::requestPropertyChange(const char *property)
调用此函数可请求托管此 ActiveX 控件的客户端允许更改属性property 。如果客户端允许更改,则返回 true;否则返回 false。
通常在property 的写入函数中首先调用此函数,如果函数返回 false,则放弃写入。
void MyActiveQt::setText(const QString &text) { if (!requestPropertyChange("text")) return; // update property propertyChanged("text"); }
另请参阅 propertyChanged()。
[virtual]
bool QAxBindable::writeData(QIODevice *sink)
如果 COM 对象支持 MIME 类型,则调用此函数将 COM 对象存储到sink 中。在写入sink 之前,必须先打开 。
返回 true 表示成功。如果函数返回 false,则 ActiveQt 将通过存储属性值来序列化对象。
如果重新实现该函数,还必须实现readData()。默认实现不执行任何操作,并返回 false。
另请参见 readData()。
© 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.