c++ - Qt ActiveX 数据类型

标签 c++ qt activex pass-by-reference qaxobject

我正在开发一个与 ActiveX 服务器通信的 C++/Qt 应用程序。 我尝试使用一个函数,该函数返回对 float 组的引用作为参数。函数原型(prototype)为:

Frequencies([in, out] SAFEARRAY(float)*)

我的代码是:

QList<QVariant> variantList;
object->dynamicCall("Frequencies(QList<QVariant>&)", variantList);

但不幸的是我有以下错误:Type Mismatch in Parameter. Pass an array of type string or real.

看完this document我也试过QList<QString>&QList<float>&没有成功。

ActiveX 服务器的文档说:Use a safearray of strings (VT_BSTR) or reals (VT_R8 for double or VT_R4 for float).

有什么想法吗?

谢谢!

最佳答案

http://qt-project.org/doc/qt-4.8/activeqt.html

The ActiveQt modules are part of the Qt Commercial Edition and the Open Source Versions of Qt.

http://qt-project.org/doc/qt-4.8/qaxobject.html#details

http://qt-project.org/doc/qt-4.8/qaxbase.html#details

这里引用了 QAXBase 的文档:

To call the methods of a COM interface described by the following IDL

dispinterface IControl
{
properties:
    [id(1)] BSTR text;
    [id(2)] IFontDisp *font;

methods:
    [id(6)] void showColumn([in] int i);
    [id(3)] bool addColumn([in] BSTR t);
    [id(4)] int fillList([in, out] SAFEARRAY(VARIANT) *list);
    [id(5)] IDispatch *item([in] int i);
};

use the QAxBase API like this:

QAxObject object("<CLSID>");

QString text = object.property("text").toString();
object.setProperty("font", QFont("Times New Roman", 12));

connect(this, SIGNAL(clicked(int)), &object, SLOT(showColumn(int)));
bool ok = object.dynamicCall("addColumn(const QString&)", "Column 1").toBool();

QList<QVariant> varlist;
QList<QVariant> parameters;
parameters << QVariant(varlist);
int n = object.dynamicCall("fillList(QList<QVariant>&)", parameters).toInt();

QAxObject *item = object.querySubItem("item(int)", 5);

Note that the QList the object should fill has to be provided as an element in the parameter list of QVariants.

所以基本上您需要确保嵌套 QList,以便使您的 SAFEARRAY 正常工作。

希望对您有所帮助。

关于c++ - Qt ActiveX 数据类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16665627/

相关文章:

c++ - 什么是 cin.peek,它有什么作用?

c++ - 未初始化的值 - Valgrind

COM/OLE/ActiveX/IDispatch混淆

javascript - 使用 JavaScript 的 ActiveX DLL

c++ - 将 unsigned char * 转换为 hexstring

c++ - 如何向量化 data_i16[0 到 15]?

c++ - 调用QSqlTableModel setTable方法时出现"Unable to find table"错误

c++ - Qt4:从 QAbstractTableModel 中读取默认的 mimeData

c++ - QPainter怎么转? (从工厂函数中 move 一个对象)

基于浏览器的游戏的 AJAX 与 ActiveX/Flash