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 框架 .