The QAxContainer 模块属于 ActiveQt 框架。它提供库实现 QWidget 子类, QAxWidget 充当 ActiveX 控件容器,和 QObject 子类, QAxObject 可以用于轻松访问非视觉 COM (组件对象模型) 对象。可以使用由这些类嵌入的脚本化 COM 对象透过 QAxScript , QAxScriptManager and QAxScriptEngine 类,和一组 tools 使之易于以编程方式访问 COM 对象。
模块由 6 个类组成
某些 范例应用程序 使用标准 ActiveX 控件来提供高级用户界面功能。
话题:
要构建可以托管 COM (组件对象模型) 对象和 ActiveX 控件的 Qt 应用程序,链接应用程序到 QAxContainer 模块通过添加
QT += axcontainer
到应用程序的
.pro
文件。
The QAxContainer 库是静态的,所以,不需要重新分发任何额外文件当使用此模块时。注意,不管怎样,正使用的 ActiveX 服务器二进制文件可能未安装在目标系统中,所以,必须在应用程序安装过程中将它们与软件包一起随附并注册。
To instantiate a COM object use the QAxBase::setControl() API, or pass the name of the object directly into the constructor of the QAxBase 子类正使用的。
可以按多种格式指定控件,但最快且最强大的格式是直接使用对象的 CLSID (类 ID)。CLSID 可以预先准备对象应该在其中运行的远程计算机的有关信息,且可以包括许可控件的许可密钥。
ActiveQt prints error messages to the debug output when it encounters error situations at runtime. Usually you must run your program in the debugger to see these messages (e.g. in Visual Studio's Debug output).
The control requested in QAxBase::setControl() is not installed on this system, or is not accessible for the current user.
The control might require administrator rights, or a license key. If the control is licensed, pass the license key to QAxBase::setControl as documented.
ActiveQt provides a Qt API to the COM object, and replaces COM datatypes with Qt equivalents.
调用 COM 对象的 API 有 4 种方式:
要为想要访问的类型库生成 C++ 名称空间,使用
dumpcpp
工具。在想要使用的类型库手动运行此工具,或将它集成到构建系统通过把类型库添加到
TYPELIBS
变量在应用程序的
.pro
文件:
TYPELIBS = file.tlb
注意, dumpcpp 可能无法暴露类型库的所有 API。
将结果头文件包括在代码中,以透过生成的 C++ 类访问对象 API。见 Qutlook 范例了解更多信息。
使用 QAxBase::dynamicCall () 和 QAxBase::querySubObject () 及 QObject::setProperty () 和 QObject::property () API 可透过名称调用 COM (组件对象模型) 对象的方法和特性。使用 dumpdoc 工具能获取任何 COM 对象及其子对象的 Qt API 文档编制;注意,并非所有 COM 对象的 API 都可用。
Qt 应用程序可以托管系统中安装的任何 ActiveScript 引擎。脚本引擎则可以运行访问 COM (组件对象模型) 对象的脚本代码。
要实例化脚本引擎,使用 QAxScriptManager::addObject () 注册想要从脚本访问的 COM 对象,和 QAxScriptManager::load () 将脚本代码加载到引擎中。然后调用脚本函数使用 QAxScriptManager::call () 或 QAxScript::call ().
透过脚本哪些 COM 对象 API 是可用的,从属所用脚本语言。
The ActiveX 测试容器 演示脚本文件的加载。
要调用无法凭借任何上述方法访问的 COM 对象的函数是可能的,直接请求 COM 接口使用
QAxBase::queryInterface
()。要获得各自接口类的 C++ 定义,使用
#import
指令采用由控件提供的类型库;见编译器手册了解细节。
ActiveQt prints error messages to the debug output when it encounters error situations at runtime. Usually you must run your program in the debugger to see these messages (e.g. in Visual Studio's Debug output).
A QAxBase::dynamicCall () 失败 - 函数原型不匹配对象 API 中的任何可用函数。
A QAxBase::dynamicCall () 失败 - 函数原型正确,但提供的参数太少。
A
QAxBase::dynamicCall
() 失败 - 函数原型正确,但参数在索引
n
类型错误,且无法强制为正确类型。
You try to call a function that is provided through an engine that doesn't provide introspection (ie. ActivePython or ActivePerl). You need to call the function directly on the respective QAxScript 对象。
另请参阅 ActiveQt 框架 .