QAxBindable 类

The QAxBindable 类提供接口介于 QWidget 和 ActiveX 客户端。 更多...

头: #include <QAxBindable>
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 )

详细描述

The QAxBindable 类提供接口介于 QWidget 和 ActiveX 客户端。

由此类提供的函数允许 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 子类。

The ActiveQt OpenGL 范例展示如何使用 QAxBindable 以实现额外 COM 接口。

另请参阅 QAxAggregated , QAxFactory ,和 ActiveQt 框架 .

成员函数文档编制

QAxBindable:: QAxBindable ()

构造空的 QAxBindable 对象。

[virtual] QAxBindable:: ~QAxBindable ()

销毁 QAxBindable 对象。

[protected] IUnknown *QAxBindable:: clientSite () const

返回指向此 ActiveX 对象的客户端站点接口的指针,或 null 若未设置客户端站点。

调用 QueryInterface() 在返回接口以获取想要调用的接口。

[virtual] QAxAggregated *QAxBindable:: createAggregate ()

Reimplement this function when you want to implement additional COM interfaces in the ActiveX control, or when you want to provide alternative implementations of COM interfaces. Return a new object of a QAxAggregated 子类。

默认实现返回 null 指针。

[protected] void QAxBindable:: propertyChanged (const char * property )

调用此函数以通知托管此 ActiveX 控件的客户端特性 property 已改变。

通常在特性写入函数末尾调用此函数。

另请参阅 requestPropertyChange ().

[virtual] bool QAxBindable:: readData ( QIODevice * source , const QString & format )

If the COM object supports a MIME type then this function is called to initialize the COM object from the data source in format 。必须打开 source for reading before you can read from it.

返回 true 指示成功。若函数返回 false,那么 ActiveQt will process the data by setting the properties through the meta object system.

若重实现此函数,还必须实现 writeData ()。默认实现什么都不做并返回 false。

警告: ActiveX 控件嵌入 HTML 可以使用 type and data 属性在 object tag to read data, or use a list of param tags to initialize properties. If param tags are used, then Internet Explorer will ignore the data attribute, and readData will not be called.

该函数在 Qt 4.1 引入。

另请参阅 writeData ().

void QAxBindable:: reportError ( int code , const QString & src , const QString & desc , const QString & context = QString())

Reports an error to the client application. code is a control-defined error code. desc is a human-readable description of the error intended for the application user. src is the name of the source for the error, typically the ActiveX server name. context can be the location of a help file with more information about the error. If context ends with a number in brackets, e.g. [12], this number will be interpreted as the context ID in the help file.

[protected] bool QAxBindable:: requestPropertyChange (const char * property )

调用此函数请求权限以更改特性 property 从托管此 ActiveX 控件的客户端。返回 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。

该函数在 Qt 4.1 引入。

另请参阅 readData ().