0

我正在尝试将 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 做到这一点?

4

1 回答 1

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();
于 2013-06-17T07:29:49.763 回答