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

posted on 2020-04-23 10:19  liujx2019  阅读(1197)  评论(0编辑  收藏  举报

导航