gpt4 book ai didi

c++ - Qt 中 _variant_t 的等价物

转载 作者:行者123 更新时间:2023-11-28 07:33:46 24 4
gpt4 key购买 nike

我正在尝试将 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 怎么做?

最佳答案

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

关于c++ - Qt 中 _variant_t 的等价物,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17142156/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com