我正在尝试将Visual-C ++代码翻译为Qt。
是否有等效的_variant_t
?
代码是:
//
// Get safarray containing all vectors from multibuffer
//
_variant_t vaArray(function->GetAllValues(TRUE)); // Take ownership of the variant - no copying
SAFEARRAY* psa = psa = V_ARRAY(&vaArray);
//
// Check dimension and size
//
ASSERT(SafeArrayGetDim(psa) == 2); // We expect 2 dimensions
long nMaxXIndex, nMaxZIndex;
SafeArrayGetUBound(psa, 1, &nMaxXIndex);
SafeArrayGetUBound(psa, 2, &nMaxZIndex);
//
// Use array
//
double* pData;
HRESULT hr = SafeArrayAccessData(psa, (void HUGEP**)&pData);
如何使用Qt?
答案 0 :(得分:1)
Qt的等价物是QVariant
(容易猜到)。这个伪代码说明了它可能需要的功能:
QVariant va_array = some_function();
QVariantList array = va_array.toList();
int dimension1 = array.count();
int dimension2 = 0;
if (dimension1 > 0) {
dimension2 = array[0].toList().count();
}
int i = 42, j = 24;
double array_item = array[i].toList()[j].toDouble();