[SOLVED] cannot convert from 'QString' to 'LPCWSTR' ???
-
I am working on an app where I need to display the file system format of the SD card. Since I couldnt find any Qt API's for it, I choose a windows API GetVolumeInformation and did it as follows:
@TCHAR volumeName[MAX_PATH + 1] = { 0 };
TCHAR fileSystemName[MAX_PATH + 1] = { 0 };
DWORD serialNumber = 0;
DWORD maxComponentLen = 0;
DWORD fileSystemFlags = 0;LPCWSTR path = deviceData->m_strPath;
if (GetVolumeInformation(
path,
volumeName,
ARRAYSIZE(volumeName),
&serialNumber,
&maxComponentLen,
&fileSystemFlags,
fileSystemName,
ARRAYSIZE(fileSystemName)))
{
qDebug()<<fileSystemName[0];
qDebug()<<fileSystemName[1];
qDebug()<<fileSystemName[2];
qDebug()<<fileSystemName[3];
qDebug()<<fileSystemName[4];
}@path indicates the SD card path and when I run the app, it throws the following error:
"cannot convert from 'QString' to 'LPCWSTR'". Where am i making a mistake??? Please help!! -
See "QString::fromWCharArray":http://qt-project.org/doc/qt-5.0/qtcore/qstring.html#fromWCharArray
@
qDebug()<<QString::fromWCharArray(fileSystemName[0]);
...
@ -
Nevermind I got the solution.
LPCWSTR path = deviceData->m_strPath.utf16();
-
Hi,
I suppose the error is on line 7, you have to convert the QString to an LPCWSTR, IIRC using "toWCharArray":http://qt-project.org/doc/qt-4.8/qstring.html#toWCharArray should do the trick
-
Thank you SGaist :)
[quote author="SGaist" date="1363091161"]Hi,
I suppose the error is on line 7, you have to convert the QString to an LPCWSTR, IIRC using "toWCharArray":http://qt-project.org/doc/qt-4.8/qstring.html#toWCharArray should do the trick[/quote]
-
My output now displays 70 65 84 51 50. If anyone wants it in a string format use as follows:
QString::fromUtf16(fileSystemName);