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

猜你喜欢

转载自www.cnblogs.com/liujx2019/p/12758955.html
今日推荐