Hello every one,
I'm trying to use a Windows COM object and I'm having trouble casting a returned function value. I am using Qt 5.7.0 and I got .h and .cpp file for COM object with dumpcpp tool. For simplicity I show only the kind of interest:
class SCAPILIB_EXPORT IAttrList
: public QAxObject{
public:
IAttrList
(IDispatch
*subobject
= 0,
QAxObject *parent
= 0) {
internalRelease();
}
/*
Method AddItem
method AddItem
*/
inline void AddItem(Attr Attribute, const QVariant& value);
/*
Method FindItemIndex
method FindItemIndex
*/
inline int FindItemIndex(int startIndex, SCAPILib::Attr Attribute);
/*
Method GetCount
method GetCount
*/
inline int GetCount();
/*
Method GetIndex
method GetIndex
*/
inline QVariant GetIndex
(int index, Attr
& pAttribute
);
/*
Method GetItem
method GetItem
*/
inline QVariant GetItem
(Attr Attribute
);
/*
Method OutputToString
method OutputToString
*/
/*
Method RestoreFromBlob
method RestoreFromBlob
*/
inline void RestoreFromBlob
(QVariant blob
);
/*
Method SaveToBlob
method SaveToBlob
*/
inline void SaveToBlob(QVariant& pBlob);
/*
Method SetIndex
method SetIndex
*/
inline void SetIndex(int index, SCAPILib::Attr Attribute, const QVariant& value);
// meta object functions
virtual const QMetaObject *metaObject
() const { return &staticMetaObject;
} virtual void *qt_metacast(const char *);
};
class SCAPILIB_EXPORT IAttrList : public QAxObject
{
public:
IAttrList(IDispatch *subobject = 0, QAxObject *parent = 0)
: QAxObject((IUnknown*)subobject, parent)
{
internalRelease();
}
/*
Method AddItem
method AddItem
*/
inline void AddItem(Attr Attribute, const QVariant& value);
/*
Method FindItemIndex
method FindItemIndex
*/
inline int FindItemIndex(int startIndex, SCAPILib::Attr Attribute);
/*
Method GetCount
method GetCount
*/
inline int GetCount();
/*
Method GetIndex
method GetIndex
*/
inline QVariant GetIndex(int index, Attr& pAttribute);
/*
Method GetItem
method GetItem
*/
inline QVariant GetItem(Attr Attribute);
/*
Method OutputToString
method OutputToString
*/
inline QString OutputToString();
/*
Method RestoreFromBlob
method RestoreFromBlob
*/
inline void RestoreFromBlob(QVariant blob);
/*
Method SaveToBlob
method SaveToBlob
*/
inline void SaveToBlob(QVariant& pBlob);
/*
Method SetIndex
method SetIndex
*/
inline void SetIndex(int index, SCAPILib::Attr Attribute, const QVariant& value);
// meta object functions
static const QMetaObject staticMetaObject;
virtual const QMetaObject *metaObject() const { return &staticMetaObject; }
virtual void *qt_metacast(const char *);
};
To copy to clipboard, switch view to plain text mode
template<>
struct QMetaTypeFunctionHelper<SCAPILib::IAttrList, /* Accepted */ true> {
static void Destruct(void *t)
{
Q_UNUSED(t)
static_cast<SCAPILib::IAttrList*>(t)->SCAPILib::IAttrList::~IAttrList();
}
static void *Construct(void *where, const void *t)
{
Q_ASSERT(!t);
Q_UNUSED(t)
return new (where) SCAPILib::IAttrList;
}
#ifndef QT_NO_DATASTREAM
static void Save
(QDataStream &stream,
const void *t
) { stream <<
*static_cast<const SCAPILib
::IAttrList*>
(t
);
} static void Load
(QDataStream &stream,
void *t
) { stream >>
*static_cast<SCAPILib
::IAttrList*>
(t
);
} #endif // QT_NO_DATASTREAM
};
template<>
struct QMetaTypeFunctionHelper<SCAPILib::IAttrList, /* Accepted */ true> {
static void Destruct(void *t)
{
Q_UNUSED(t)
static_cast<SCAPILib::IAttrList*>(t)->SCAPILib::IAttrList::~IAttrList();
}
static void *Construct(void *where, const void *t)
{
Q_ASSERT(!t);
Q_UNUSED(t)
return new (where) SCAPILib::IAttrList;
}
#ifndef QT_NO_DATASTREAM
static void Save(QDataStream &stream, const void *t) { stream << *static_cast<const SCAPILib::IAttrList*>(t); }
static void Load(QDataStream &stream, void *t) { stream >> *static_cast<SCAPILib::IAttrList*>(t); }
#endif // QT_NO_DATASTREAM
};
To copy to clipboard, switch view to plain text mode
The function GetItem always returned a QVariant, usually the QVariant contain a QString, QInt or QBool, but with a determinate attribute the returned value will be a pointer to the base class(IAttrList *).
inline QVariant IAttrList
::GetItem(Attr Attribute
) {
void *_a[] = {(void*)&qax_result, (void*)&Attribute};
return qax_result;
}
inline QVariant IAttrList::GetItem(Attr Attribute)
{
QVariant qax_result;
void *_a[] = {(void*)&qax_result, (void*)&Attribute};
qt_metacall(QMetaObject::InvokeMetaMethod, 12, _a);
return qax_result;
}
To copy to clipboard, switch view to plain text mode
I can use the function of the COM object just fine, except when it will be return a indicated class pointer. In this case de QVariant returnet type is (IUnknown *) and I not able to cast this to (IAttrLits *).
I'm tried with:
IAttrList * Attr = AttrList.GetItem(Some_Attribute).Value<IAttrList *>();
IAttrList * Attr = AttrList.GetItem(Some_Attribute).Value<IAttrList *>();
To copy to clipboard, switch view to plain text mode
But compiler returned error: static assertion failed: qobject_cast requires the type to have a Q_OBJECT macro
Which I understand is normal because, according to QT documentation, classes derived from QAxObject can not contain the Q_OBJECT macro.
I have also tried with:
IAttrList * attr = static_cast<IAttrList *>(AttrList.GetItem(Some_attribute).data());
IAttrList * attr = static_cast<IAttrList *>(AttrList.GetItem(Some_attribute).data());
To copy to clipboard, switch view to plain text mode
and
IAttrList * attr = static_cast<IAttrList *>(AttrList.GetItem(Some_attribute).value<void *>();
IAttrList * attr = static_cast<IAttrList *>(AttrList.GetItem(Some_attribute).value<void *>();
To copy to clipboard, switch view to plain text mode
It's compile but the AttrList pointer does not seem to be valid because I get a segmentation fault to try use it.
I have also read about the QueryInterface method and I have tried with something like:
QVariant * var
=AttrList.
GetItem(some_attribute
);
HRESULT hr = AttrList.queryInterface(UuID,(void **)&var);
QVariant * var =AttrList.GetItem(some_attribute);
HRESULT hr = AttrList.queryInterface(UuID,(void **)&var);
To copy to clipboard, switch view to plain text mode
The problen is that this interface not have a UUID and I can't do the call.
Also I have read about get a class instance with QuerySubOject but a QVariant Objects does not have it.
I do not know how to solve it, any subgestion?. Thanks in advanced.
Bookmarks