I have been using a ActiveX widget in my C++ program using the QAxWidget class. It works fine for all the functions that return a single value and have input arguments only. However, when I try to pass a variable by reference which I will use later as a return value, it won't compile because QVariant can't be instantiated with a pointer or it has errors at runtime. The documenation for the ActiveX widget I'm using is geared for Visual Basic so I'm probably using the wrong syntax. Here is a function that works:

************** LIBRARY DOCUMENTATION **************
Motor Method SetAbsMovePos

See Also Example Code


Visual Basic Syntax

Function SetAbsMovePos(lChanID As Long, fAbsPos As Single) As Long


Parameters

lChanID - the channel identifier

fAbsPos - the absolute position associated with the specified channel


Returns

MG Return Code


Details

This method sets the absolute position to which the channel specified by the lChanID parameter will move, the next time the MoveAbsolute method is called. The position is set to the value specified in the fAbsPos parameter and is measured from the home position, in real world units (mm or degrees).

The lChanID parameter takes values specified by the HWCHANNEL enumeration.

Note: On dual channel units, the system cannot set the absolute position of both channels simultaneously, and the use of CHANBOTH_ID is not allowed.

To get the absolute position for a particular channel, see the GetAbsMovePos method.
************** MY FUNCTIONING IMPLEMENTATION **************
Qt Code:
  1. QAxWidget* hMotor;
  2. hMotor = new QAxWidget();
  3. hMotor->setControl("MGMOTOR.MGMotorCtrl.1");
  4. hMotor->setProperty("HWSerialNum",QVariant(67839858));
  5. hMotor->dynamicCall("StartCtrl");
  6. double pos(10);
  7.  
  8. hMotor->dynamicCall("SetAbsMovePos(QVariant,QVariant)",chanID,QVariant(pos));
  9.  
  10. hMotor->dynamicCall("MoveAbsolute(QVariant,QVariant,QVariant)",chanID,1);
To copy to clipboard, switch view to plain text mode 



************** FUNCTION I WANT TO USE **************
Motor Method GetPosition

See Also Example Code


Visual Basic Syntax

Function GetPosition(lChanID As Long, pfPosition As Single) As Long


Parameters

lChanID - the channel identifier

pfPosition - the current position of the associated channel


Returns

MG Return Code


Details

This method obtains the present position for the channel(s) specified by the lChanID parameter, and returns a value in the pfPosition parameter.

If a calibration file has been associated with the channel using the APT Config utility, the method returns the calibrated position. If no calibration file has been associated, then the returned position is uncalibrated. Refer to the helpfile in the APT Config utility for further details on using position calibration files.

Note that the position values returned are derived from either the ‘Microstep Count’ or the Encoder Count, dependent on the positioning mode selected. See the encoder operation section for more information.

The position of the stage associated with the specified channel is determined by its displacement from the 'Home' position.

The lChanID parameter takes values specified by the HWCHANNEL enumeration.

************** MY SYNTAX ATTEMPTS AND ERROR OUTPUT **************
Qt Code:
  1. #include <QApplication>
  2. #include <QAxWidget>
  3. #include <QDebug>
  4. #include <QThread>
  5.  
  6. int main(int argc, char *argv[])
  7. {
  8. QApplication g(argc,argv);
  9.  
  10. QAxWidget hMotor;
  11. QVariant chanID = QVariant(0);
  12. hMotor.setControl("MGMOTOR.MGMotorCtrl.1");
  13. hMotor.setProperty("HWSerialNum",QVariant(67839858));
  14. hMotor.dynamicCall("StartCtrl");
  15. hMotor.dynamicCall("EnableHWChannel(QVariant)",chanID);
  16. QThread::sleep(1); // Give it time to enable the channel
  17.  
  18. double pos(5);
  19. hMotor.dynamicCall("SetAbsMovePos(QVariant,QVariant)",chanID,QVariant(pos));
  20. hMotor.dynamicCall("MoveAbsolute(QVariant,QVariant,QVariant)",chanID,0);
  21.  
  22. double outPos;
  23. hMotor.dynamicCall("GetPosition(QVariant,QVariant)",chanID,QVariant(outPos));
  24. qWarning() << outPos;
  25. hMotor.dynamicCall("StopCtrl");
  26.  
  27.  
  28. return (0);
  29.  
  30. }
To copy to clipboard, switch view to plain text mode 

CONSOLE OUTPUT
QAxBase: Error calling IDispatch member GetPosition: Type mismatch in parameter
1
1.39065e-309
Press <RETURN> to close this window...

All the functions work except the "GetPosition" one. The outPos should a double between 0 and 100, not 1.39e-309 (bad memory). This is just a simple example and I've used the other functions probably 100 times and I'm sure they work. If I try QVariant(&outPos) as the argument, I get a compile error (QVariant::QVariant(*void) is private...). Any ideas?

Thanks in advance!