PDA

View Full Version : ActiveQt QVariant and VC VARIANT



dbzhang800
22nd September 2009, 03:23
Hello everyone,

I want to call an activeX component through activeQt, but I don't know how to deal with VARIANT.

In VC++ 6;


void DoGo(short nNumberOfAxes, const VARIANT& nAxisArray);


example code:



const int nSize(3);
short nAxesArray[nSize] = { 0, 1, 2};
COleSafeArray arrAxes;
arrAxes.CreateOneDim(VT_I2,nSize,nAxesArray);
MintController1.DoGo (3, arrAxes);



In Qt, What I get is:




void DoGo (int nNumberOfAxes, QVariant nAxisArray) [slot]

call the function directly:

QVariantList params = ...
object->dynamicCall("DoGo(int, QVariant)", params);


So, anyone can give me an example code. I don't know how to write params


Please help.

Thanks.

kwisp
22nd September 2009, 06:27
try QString QAxBase::generateDocumentation ()
and find analog COleSafeArray in Qt
may be QVector ?

dbzhang800
22nd September 2009, 11:35
Documentation string generated by QString QAxBase::generateDocumentation () :


void DoGo (int nNumberOfAxes, QVariant nAxisArray) [slot]

For more information, see help context 0 in C:\Program Files\WorkBench v5\MintControls.hlp.

Connect a signal to this slot:

QObject::connect(sender, SIGNAL(someSignal(int, QVariant)), object, SLOT(DoGo(int, QVariant)));

Or call the function directly:

QVariantList params = ...
object->dynamicCall("DoGo(int, QVariant)", params);

function generated through dumpcpp -getdoc is:


inline void _DMintControllerCtrl::DoGo(int nNumberOfAxes, const QVariant& nAxisArray)
{
void *_a[] = {0, (void*)&nNumberOfAxes, (void*)&nAxisArray};
qt_metacall(QMetaObject::InvokeMetaMethod, 176, _a);
}

I try to use QVector, but I don't know how to cast QVector to QVariant

Any suggestion?

kwisp
22nd September 2009, 13:16
may be
QVariant ( const QList<QVariant> & val )

dbzhang800
23rd September 2009, 01:19
Thanks for your help. But This still doesnot work.

I get runtime error:

QAxBase: Error calling IDispatch member DoGo: Unknown error

kwisp
23rd September 2009, 06:15
QVariant qVariantFromValue ( const T & value )
QVariant QVariant::fromValue ( const T & value ) [static]
?
and
QVariant::QVariant ( int typeOrUserType, const void * copy )
void QVariant::setValue ( const T & value )
T QVariant::value () const
?

kwisp
23rd September 2009, 06:15
show your code please

dbzhang800
23rd September 2009, 11:27
mint->dynamicCall("DoGo(int, QVariant)", QVariantList()<<3<<QVariant(QVariantList()<<0<<1<<2));

Or



short aaa[3] = {0,1,2};
mint->dynamicCall("DoGo(int, QVariant)", QVariantList()<<3<<QVariant(QMetaType::Short,(void *)aaa));

will get runtime error:

QAxBase: Error calling IDispatch member DoGo: Unknown error


short aaa[3] = {0,1,2};
QVariant params;
params.setValue(aa);

will get compile error:
error C2039: 'qt_metatype_id' : is not a member of 'QMetaTypeId<T>'

kwisp
23rd September 2009, 11:53
2
3



short aaa[3] = {0,1,2};
QVariant params;
params.setValue(aa);
:)
may be.


QVector<int> vec;
vec<<10<<20<<30;
QVariant var;
var.setValue(vec);

dbzhang800
23rd September 2009, 15:15
QVector<int> vec;
vec<<10<<20<<30;
QVariant var;
var.setValue(vec);

but the code still does not work :(


d:\qt\4.5.2-msvc\include\qtcore\../../src/corelib/kernel/qmetatype.h(189) : error C2039: 'qt_metatype_id' : is not a member of 'QMetaTypeId<T>'
with
[
T=QVector<int>
]

kwisp
23rd September 2009, 15:24
oh-ho-ho
read about setValue().
assistant tell you about it.

dbzhang800
24th September 2009, 14:55
The function info:

DoGo
Named Params = u'nNumberOfAxes, nAxisArray'
Return Type = 'Void'
Argument = 'Integer 2'
Argument = 'Variant'
Function kind = 'Dispatch'
Invoke Kind = 'Function'
Number Optional Params = 0

and i try to use queryInterface.

Other function which without a VARIANT parameter works fine.
But this one, I still do not know how to deal with the VARIANT



IUnknown *iface = 0;
mint->queryInterface(IID_IUnknown, (void**)&iface);
if (iface)
{
short axes[3]={0,1,2};
VARIANTARG v[2];
v[1].iVal = 3;
v[1].vt = VT_I2;
v[0].piVal = axes
v[0].vt = VT_BYREF|VT_I2;

DISPPARAMS params = {v, NULL, 2, 0};

iface->Invoke(dispid, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD,&params ,NULL, NULL, NULL);
}


any idea?

dbzhang800
25th September 2009, 02:13
:):) The following code works now.



IUnknown *iface = 0;
mint->queryInterface(IID_IUnknown, (void**)&iface);
if (iface)
{
DISPID dispid;
OLECHAR * dispname = L"DoGo";
iface->GetIDsOfNames(IID_NULL, &dispname, 1, LOCALE_USER_DEFAULT, &dispid);

short axes0[3]={0,1,2};
SAFEARRAY *axes;
SAFEARRAYBOUND axesbound[1];
axesbound[0].lLbound = 0;
axesbound[0].cElements = 3;
axes = ::SafeArrayCreate(VT_I2, 1, axesbound);
for(long index=0;index<3;index++)
{
::SafeArrayPutElement(axes,&index,axes0+index);
}

VARIANTARG v[2];
v[1].iVal = 3; //number of axes
v[1].vt = VT_I2;
v[0].parray = axes;
v[0].vt = VT_ARRAY|VT_I2;

DISPPARAMS params = {v, NULL, 2, 0};

iface->Invoke(dispid, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD,&params ,NULL, NULL, NULL);
}

:( but I still do not know hou to deal with it through ActiveQt method.


QVariantList params = ...
object->dynamicCall("DoGo(int, QVariant)", params);

kwisp
28th September 2009, 07:09
in files
E:\Qt\4.5.2\src\activeqt\shared\qaxtypes.cpp
function
QVariant VARIANTToQVariant(const VARIANT &arg, const QByteArray &typeName, uint type)
help you to understand how yuo must do it.
see the code.

kwisp
28th September 2009, 07:43
http://www.qtcentre.org/forum/p-variant-qvariant-post117209/postcount2.html

Maxbester
19th June 2013, 13:50
http://www.qtcentre.org/forum/p-variant-qvariant-post117209/postcount2.html

Your link is dead. Could you update it? Thanks.

Added after 52 minutes:


:):) The following code works now.



IUnknown *iface = 0;
mint->queryInterface(IID_IUnknown, (void**)&iface);
if (iface)
{
// ...
}

Could you comment a bit your code? Thanks