0

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?

Maxbester
  • 2,435
  • 7
  • 42
  • 70

1 Answers1

1

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();
Pavel Strakhov
  • 39,123
  • 5
  • 88
  • 127
  • Just one question. In my example, I can access entries like: `for(int i=0; i – Maxbester Jun 17 '13 at 08:01
  • It depends on how do you store your bidirectional array. If it's actually stored in a flat array, then it should be like `array[dimension1 * j + i].toDouble()`. – Pavel Strakhov Jun 17 '13 at 08:09