Pergunta

I am trying to translate a Visual-C++ code to Qt.

Is there an equivalent of _variant_t?

The code is:

//  
// 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);

How to do it with Qt?

Foi útil?

Solução

The Qt's equivalent is QVariant (easy to guess). This pseudo code illustrates its abilities you may need:

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();
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top