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