Results 1 to 16 of 16

Thread: ActiveQt QVariant and VC VARIANT

  1. #1
    Join Date
    Aug 2009
    Posts
    52
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question ActiveQt QVariant and VC VARIANT

    Hello everyone,

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

    In VC++ 6;

    Qt Code:
    1. void DoGo(short nNumberOfAxes, const VARIANT& nAxisArray);
    To copy to clipboard, switch view to plain text mode 


    example code:


    Qt Code:
    1. const int nSize(3);
    2. short nAxesArray[nSize] = { 0, 1, 2};
    3. COleSafeArray arrAxes;
    4. arrAxes.CreateOneDim(VT_I2,nSize,nAxesArray);
    5. MintController1.DoGo (3, arrAxes);
    To copy to clipboard, switch view to plain text mode 



    In Qt, What I get is:


    Qt Code:
    1. void DoGo (int nNumberOfAxes, QVariant nAxisArray) [slot]
    2.  
    3. call the function directly:
    4.  
    5. QVariantList params = ...
    6. object->dynamicCall("DoGo(int, QVariant)", params);
    To copy to clipboard, switch view to plain text mode 


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


    Please help.

    Thanks.

  2. #2
    Join Date
    Dec 2008
    Location
    TaganrogNativelandChehov,Russia
    Posts
    64
    Thanks
    1
    Thanked 8 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: ActiveQt QVariant and VC VARIANT

    try QString QAxBase::generateDocumentation ()
    and find analog COleSafeArray in Qt
    may be QVector ?
    east or west home is best

  3. #3
    Join Date
    Aug 2009
    Posts
    52
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: ActiveQt QVariant and VC VARIANT

    Documentation string generated by QString QAxBase::generateDocumentation () :

    Qt Code:
    1. void DoGo (int nNumberOfAxes, QVariant nAxisArray) [slot]
    2.  
    3. For more information, see help context 0 in C:\Program Files\WorkBench v5\MintControls.hlp.
    4.  
    5. Connect a signal to this slot:
    6.  
    7. QObject::connect(sender, SIGNAL(someSignal(int, QVariant)), object, SLOT(DoGo(int, QVariant)));
    8.  
    9. Or call the function directly:
    10.  
    11. QVariantList params = ...
    12. object->dynamicCall("DoGo(int, QVariant)", params);
    To copy to clipboard, switch view to plain text mode 

    function generated through dumpcpp -getdoc is:

    Qt Code:
    1. inline void _DMintControllerCtrl::DoGo(int nNumberOfAxes, const QVariant& nAxisArray)
    2. {
    3. void *_a[] = {0, (void*)&nNumberOfAxes, (void*)&nAxisArray};
    4. qt_metacall(QMetaObject::InvokeMetaMethod, 176, _a);
    5. }
    To copy to clipboard, switch view to plain text mode 

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

    Any suggestion?

  4. #4
    Join Date
    Dec 2008
    Location
    TaganrogNativelandChehov,Russia
    Posts
    64
    Thanks
    1
    Thanked 8 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: ActiveQt QVariant and VC VARIANT

    may be
    QVariant ( const QList<QVariant> & val )
    east or west home is best

  5. #5
    Join Date
    Aug 2009
    Posts
    52
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: ActiveQt QVariant and VC VARIANT

    Thanks for your help. But This still doesnot work.

    I get runtime error:

    QAxBase: Error calling IDispatch member DoGo: Unknown error

  6. #6
    Join Date
    Dec 2008
    Location
    TaganrogNativelandChehov,Russia
    Posts
    64
    Thanks
    1
    Thanked 8 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: ActiveQt QVariant and VC VARIANT

    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
    ?
    east or west home is best

  7. #7
    Join Date
    Dec 2008
    Location
    TaganrogNativelandChehov,Russia
    Posts
    64
    Thanks
    1
    Thanked 8 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: ActiveQt QVariant and VC VARIANT

    show your code please
    east or west home is best

  8. #8
    Join Date
    Aug 2009
    Posts
    52
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: ActiveQt QVariant and VC VARIANT

    Qt Code:
    1. mint->dynamicCall("DoGo(int, QVariant)", QVariantList()<<3<<QVariant(QVariantList()<<0<<1<<2));
    To copy to clipboard, switch view to plain text mode 

    Or

    Qt Code:
    1. short aaa[3] = {0,1,2};
    2. mint->dynamicCall("DoGo(int, QVariant)", QVariantList()<<3<<QVariant(QMetaType::Short,(void *)aaa));
    To copy to clipboard, switch view to plain text mode 

    will get runtime error:

    QAxBase: Error calling IDispatch member DoGo: Unknown error

    Qt Code:
    1. short aaa[3] = {0,1,2};
    2. QVariant params;
    3. params.setValue(aa);
    To copy to clipboard, switch view to plain text mode 

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

  9. #9
    Join Date
    Dec 2008
    Location
    TaganrogNativelandChehov,Russia
    Posts
    64
    Thanks
    1
    Thanked 8 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: ActiveQt QVariant and VC VARIANT

    Quote Originally Posted by dbzhang800 View Post
    2
    3



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

    may be.
    Qt Code:
    1. QVector<int> vec;
    2. vec<<10<<20<<30;
    3. var.setValue(vec);
    To copy to clipboard, switch view to plain text mode 
    east or west home is best

  10. #10
    Join Date
    Aug 2009
    Posts
    52
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: ActiveQt QVariant and VC VARIANT

    Qt Code:
    1. QVector<int> vec;
    2. vec<<10<<20<<30;
    3. QVariant var;
    4. var.setValue(vec);
    To copy to clipboard, switch view to plain text mode 

    but the code still does not work

    Qt Code:
    1. 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>'
    2. with
    3. [
    4. T=QVector<int>
    5. ]
    To copy to clipboard, switch view to plain text mode 

  11. #11
    Join Date
    Dec 2008
    Location
    TaganrogNativelandChehov,Russia
    Posts
    64
    Thanks
    1
    Thanked 8 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: ActiveQt QVariant and VC VARIANT

    oh-ho-ho
    read about setValue().
    assistant tell you about it.
    east or west home is best

  12. #12
    Join Date
    Aug 2009
    Posts
    52
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: ActiveQt QVariant and VC VARIANT

    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

    Qt Code:
    1. IUnknown *iface = 0;
    2. mint->queryInterface(IID_IUnknown, (void**)&iface);
    3. if (iface)
    4. {
    5. short axes[3]={0,1,2};
    6. VARIANTARG v[2];
    7. v[1].iVal = 3;
    8. v[1].vt = VT_I2;
    9. v[0].piVal = axes
    10. v[0].vt = VT_BYREF|VT_I2;
    11.  
    12. DISPPARAMS params = {v, NULL, 2, 0};
    13.  
    14. iface->Invoke(dispid, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD,&params ,NULL, NULL, NULL);
    15. }
    To copy to clipboard, switch view to plain text mode 

    any idea?

  13. #13
    Join Date
    Aug 2009
    Posts
    52
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: ActiveQt QVariant and VC VARIANT

    The following code works now.

    Qt Code:
    1. IUnknown *iface = 0;
    2. mint->queryInterface(IID_IUnknown, (void**)&iface);
    3. if (iface)
    4. {
    5. DISPID dispid;
    6. OLECHAR * dispname = L"DoGo";
    7. iface->GetIDsOfNames(IID_NULL, &dispname, 1, LOCALE_USER_DEFAULT, &dispid);
    8.  
    9. short axes0[3]={0,1,2};
    10. SAFEARRAY *axes;
    11. SAFEARRAYBOUND axesbound[1];
    12. axesbound[0].lLbound = 0;
    13. axesbound[0].cElements = 3;
    14. axes = ::SafeArrayCreate(VT_I2, 1, axesbound);
    15. for(long index=0;index<3;index++)
    16. {
    17. ::SafeArrayPutElement(axes,&index,axes0+index);
    18. }
    19.  
    20. VARIANTARG v[2];
    21. v[1].iVal = 3; //number of axes
    22. v[1].vt = VT_I2;
    23. v[0].parray = axes;
    24. v[0].vt = VT_ARRAY|VT_I2;
    25.  
    26. DISPPARAMS params = {v, NULL, 2, 0};
    27.  
    28. iface->Invoke(dispid, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD,&params ,NULL, NULL, NULL);
    29. }
    To copy to clipboard, switch view to plain text mode 

    but I still do not know hou to deal with it through ActiveQt method.
    Qt Code:
    1. QVariantList params = ...
    2. object->dynamicCall("DoGo(int, QVariant)", params);
    To copy to clipboard, switch view to plain text mode 

  14. The following user says thank you to dbzhang800 for this useful post:

    Maxbester (19th June 2013)

  15. #14
    Join Date
    Dec 2008
    Location
    TaganrogNativelandChehov,Russia
    Posts
    64
    Thanks
    1
    Thanked 8 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: ActiveQt QVariant and VC VARIANT

    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.
    east or west home is best

  16. #15
    Join Date
    Dec 2008
    Location
    TaganrogNativelandChehov,Russia
    Posts
    64
    Thanks
    1
    Thanked 8 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: ActiveQt QVariant and VC VARIANT

    east or west home is best

  17. #16
    Join Date
    Jan 2013
    Posts
    6
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: ActiveQt QVariant and VC VARIANT

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


    Added after 52 minutes:


    Quote Originally Posted by dbzhang800 View Post
    The following code works now.

    Qt Code:
    1. IUnknown *iface = 0;
    2. mint->queryInterface(IID_IUnknown, (void**)&iface);
    3. if (iface)
    4. {
    5. // ...
    6. }
    To copy to clipboard, switch view to plain text mode 
    Could you comment a bit your code? Thanks
    Last edited by Maxbester; 19th June 2013 at 13:50.

Similar Threads

  1. Convert between a custom data type wrapped in a QVariant
    By darkadept in forum Qt Programming
    Replies: 2
    Last Post: 17th March 2009, 09:07
  2. Getting Microsoft Word Object to SaveAs
    By jvwebb in forum Newbie
    Replies: 3
    Last Post: 2nd September 2008, 19:27
  3. QVariant custom/user type comparison
    By gri in forum Qt Programming
    Replies: 2
    Last Post: 12th August 2008, 14:36
  4. Replies: 8
    Last Post: 16th July 2008, 14:05
  5. Crash caused by QVariant (mis)use
    By mclark in forum Newbie
    Replies: 2
    Last Post: 31st October 2006, 15:05

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.