Cobra91151
Cobra91151

Reputation: 650

WMI types conversion issue

I want to get ram slots memory and convert it to GB. I use WMI, Win32_PhysicalMemory class with property Capacity.

Code:

QString userRAMCapacity = QString::fromWCharArray(ramCapacity.bstrVal);

When using Qt function -

QString::fromWCharArray(ramCapacity.bstrVal); 

I get proper ram slots memory capacity in bytes, but I can't convert it to GB. I tried to use another function -

QString::number(ramCapacity.uintVal), 

it works but display the wrong memory amount. Please help to fix this issue. Thanks in advance.

Upvotes: 1

Views: 98

Answers (1)

Oleg Bogdanov
Oleg Bogdanov

Reputation: 1732

QString has toInt() method that you would need to apply before doing any math:

auto result = QString::fromWCharArray(ramCapacity.bstrVal). toLongLong() / (1024) / (1024) / (1024);

Upvotes: 1

Related Questions