[Solved]ActiveQt: retrieve list of subObjects
-
Hi,
I need to access a COM-API which has many functions returning Lists of subObjects.
The functions look like this:
@public static List<NetworkAdapter> ReadNetworkAdapters();
@Is there a way to do this with dynamicCall() or querySubObject()?
I have tried the following, but I only get an empty QVariantList
@
QVariant var=qxSystem->dynamicCall("ReadNetworkAdapters()");
qDebug()<<"type:"<<var.typeName();
qDebug()<<"count:"<<var.toList().count();@output:
type: QVariantList
count: 0Note: I have run the .Net example given by the vendor and it returns 1 NetworkAdapter.
-
After looking at the sources of the ActiveQt module I found out that VariantToQVariant only adds items to the list if the type is supported, which is not the case for IUnknown*.
To make it work for me I added a case for the type VT_Unknown, so it can return a QVariantList which stores IUnknown pointers.
Here is a snippet of the VariantToQvariant function in qaxtypes.cpp.
The added code is at line 1351 in the file(Qt 4.8.4)
@
void pElement = 0;
switch(vt) {
case VT_BSTR: Q_ASSERT(false); break; // already covered
case VT_BOOL: pElement = &variant.boolVal; break;
case VT_I1: pElement = &variant.cVal; break;
case VT_I2: pElement = &variant.iVal; break;
case VT_I4: pElement = &variant.lVal; break;
#if defined(_MSC_VER) && _MSC_VER >= 1400
case VT_I8: pElement = &variant.llVal; break;
case VT_UI8: pElement = &variant.ullVal; break;
#endif
case VT_INT: pElement = &variant.intVal; break;
case VT_UI1: Q_ASSERT(false); break; // already covered
case VT_UI2: pElement = &variant.uiVal; break;
case VT_UI4: pElement = &variant.ulVal; break;
case VT_UINT: pElement = &variant.uintVal; break;
case VT_CY: pElement = &variant.cyVal; break;
case VT_R4: pElement = &variant.fltVal; break;
case VT_R8: pElement = &variant.dblVal; break;
case VT_DATE: pElement = &variant.date; break;
//added this line to support IUnknown
case VT_UNKNOWN: pElement = &variant.punkVal; break;
case VT_VARIANT: Q_ASSERT(false); break; // already covered
default:
break;
}
if (!pElement) {
var = list;
break;
}@I am not sure if this is a Bug or just not supported for any reason.
-
Hi,
You can try to ask that on the interest mailing list, you'll find Qt's developers/maintainers there (this forum is more user oriented)
I don't think it is a bug (I may be wrong though), IIRC IUNKNOWN* can point anything so you don't know what it will be.
Did you try with registering your custom type with QVariant ?
-
Thanks, I will ask on the mailing list.
In my case having a IUnknown* is enough, because then I can create the QAxObject by passing the IUnknown* in the constructor.