QString 轉換成 wchar 的一個小陷阱


QString::toWCharArray(wchar_t * array)

其中 wchar_t * array 除了要分配內存之外,必須用 wmemset 初始化。

環境是 Visual Studio 2015.

 

QT官方文檔確實注明了:Note: This function does not append a null character to the array.

 

另一種轉換方法

auto archiveWString = mArchive.toStdWString();
auto archive = const_cast<wchar_t *>(archiveWString.c_str());

出處:VRonin https://forum.qt.io/topic/92621/convert-qstring-to-wchar_t/20


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM