2

This is a follow up to a previous question: Qt ActiveX

I am trying to use an ActiveX control in my program.

QAxWidget* mAX = new QAxWidget();
mAX->setControl("{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}");

I know that there is a function like the one below (used getDocumentation()):

SendCommand(QString input, QString& output)

But when I try to execute it:

QString returString;
mAX->dynamicCall("SendCommand(QString,QString&)","something",returnString);

I always get:

returString = "";

I searched the web and saw a similar bug which was reported on their bug tracker. It does not seem fixed yet:

Calling functions through dynamicCall() don't return values by QVariant

Also a post where someone seems to have the same problem:

QAxObject and dynamicCall

Anybody know of a solution/work around ?

EDIT:

The original function is SendCommand(LPCTSTR command,BSTR* ret).

Maybe an issue with the way the BSTR* is handled as a &QString ?

Smash
  • 3,722
  • 4
  • 34
  • 54

2 Answers2

3

you can use this solution

QString strRetVal;
QVariant returnValue("");
QVariant param1("something");
QList<QVariant> inplist;
inplist<<param1;
inplist<<returnValue;
mAX->dynamicCall("SendCommand(QString,QString&)",inplist );
strRetVal=inplist.at(1).toString();
khani_mahdi
  • 166
  • 9
  • Why pack the parameters into inplist and unpack them? I see that it works better, but I don't understand why. I tried @thomas solution above, but the return string value isn't set. When the values are packed into inplist, dynamicCall can set QString values, but not QStringList values. QStringList values still don't get set, and I get an error msg "QAxBase: Error calling IDispatch member GetPorts: Unknown error" – Steve Kolokowsky Mar 08 '16 at 21:43
2

From looking at the documentation, you are not calling the function correctly. You are passing in a QString, yet the function takes a QVariant. Since QVariant doesn't have explicit constructors (by design), a temporary QVariant is created and passed to dynamicCall. As a consequence your returnValue doesn't get updated.

QVariant dynamicCall( const char * function, const QVariant & var1 = QVariant(), ...
                    , const QVariant & var8 = QVariant() )

I think that everything will work when you use a QVariant instead.

 QVariant returnValue;
 mAX->dynamicCall("SendCommand(QString,QString&)", "something", returnValue );
Thomas
  • 4,980
  • 2
  • 15
  • 30