Il 09/11/2017 10:15, Nikos Chantziaras ha scritto:
This saves an allocation, a copy and a free since I don't have to use
QString::toWCharArray(). However, is this actually safe? "It seems to
work," and AFAIK, QString::d->data() is already in the format and
encoding Windows excepts a wchar_t* to be. Is this correct?

It is safe. QString is UTF-16 encoded (same code unit size as for wchar_t on Windows), and Windows APIs accepting wchar_t expect a NUL-terminated UTF-16 string as a wchar_t*, which is exactly what utf16() provides.

See also various of such usages into Qt itself, e.g.

https://code.woboq.org/qt5/qtbase/src/corelib/io/qfilesystemengine_win.cpp.html#387


Cheers,
--
Giuseppe D'Angelo | giuseppe.dang...@kdab.com | Senior Software Engineer
KDAB (UK) Ltd., a KDAB Group company | Tel: UK +44-1625-809908
KDAB - Qt, C++ and OpenGL Experts

Attachment: smime.p7s
Description: Firma crittografica S/MIME

_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to