Qt调用COM组件 笔记

42 篇文章 1 订阅


dynamicCall   既可以调用COM方法,也可以设置属性

QVariant QAxBase::dynamicCall ( const char * function, const QVariant & var1 = QVariant(), const QVariant & var2 = QVariant(), const QVariant & var3 = QVariant(), const QVariant & var4 = QVariant(), const QVariant & var5 = QVariant(), const QVariant & var6 = QVariant(), const QVariant & var7 = QVariant(), const QVariant & var8 = QVariant() )

Calls the COM object's method function, passing the parameters var1, var1, var2, var3, var4, var5, var6, var7 and var8, and returns the value returned by the method, or an invalid QVariant if the method does not return a value or when the function call failed.


If function is a method of the object the string must be provided as the full prototype, for example as it would be written in a QObject::connect() call.


 activeX->dynamicCall("Navigate(const QString&)", "qt.nokia.com");
Alternatively a function can be called passing the parameters embedded in the string, e.g. above function can also be invoked using


 activeX->dynamicCall("Navigate(\"qt.nokia.com\")");
All parameters are passed as strings; it depends on the control whether they are interpreted correctly, and is slower than using the prototype with correctly typed parameters.


If function is a property the string has to be the name of the property. The property setter is called when var1 is a valid QVariant, otherwise the getter is called.


 activeX->dynamicCall("Value", 5);
 QString text = activeX->dynamicCall("Text").toString();
Note that it is faster to get and set properties using QObject::property() and QObject::setProperty().


dynamicCall() can also be used to call objects with a disabled metaobject wrapper, which can improve performance significantely, esp. when calling many different objects of different types during an automation process. ActiveQt will then however not validate parameters.


It is only possible to call functions through dynamicCall() that have parameters or return values of datatypes supported by QVariant. See the QAxBase class documentation for a list of supported and unsupported datatypes. If you want to call functions that have unsupported datatypes in the parameter list, use queryInterface() to retrieve the appropriate COM interface, and use the function directly.


 IWebBrowser2 *webBrowser = 0;
 activeX->queryInterface(IID_IWebBrowser2, (void **)&webBrowser);
 if (webBrowser) {
     webBrowser->Navigate2(pvarURL);
     webBrowser->Release();
 }
This is also more efficient.


QVariant QAxBase::dynamicCall ( const char * function, QList<QVariant> & vars )
This is an overloaded function.


Calls the COM object's method function, passing the parameters in vars, and returns the value returned by the method. If the method does not return a value or when the function call failed this function returns an invalid QVariant object.


The QVariant objects in vars are updated when the method has out-parameters.


void QAxBase::exception ( int code, const QString & source, const QString & desc, const QString & help ) [signal]
This signal is emitted when the COM object throws an exception while called using the OLE automation interface IDispatch. code, source, desc and help provide information about the exception as provided by the COM server and can be used to provide useful feedback to the end user. help includes the help file, and the help context ID in brackets, e.g. "filename [id]".
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值