我正在开发一个与 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 ofQVariants
.
所以基本上您需要确保嵌套 QList,以便使您的 SAFEARRAY
正常工作。
希望对您有所帮助。
关于c++ - Qt ActiveX 数据类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16665627/