Computer/Programming

QString to wchar_t array

holycall 2019. 11. 27. 11:31

https://stackoverflow.com/questions/16225810/unable-to-convert-qstring-to-wchar-array/42361091#42361091

 

Unable to convert QString to WChar Array

QString processName = "test.exe"; QString::toWCharArray(processName); I'm getting the following error: error: C2664: 'QString::toWCharArray' : cannot convert parameter 1 from 'QString' to 'wchar_...

stackoverflow.com

QString을 wchar_t로 바꿀 때 채택 된 첫 번 째 답이 아니라 두 번째 답이 동작. 

QString processName = "test.exe";
wchar_t *array = new wchar_t[processName.length() + 1];
processName.toWCharArray(array);
array[processName.length()] = 0;

toStdWString().c_str() 세 번째 답이 있는데 동작을 잘 하지 않는다. 원인은 잘 모르겠다.