Portable Unicode QT Boost

From OpenMW Wiki
Jump to: navigation, search

Standard C++

std::string is byte-oriented encoding-unaware container. iostream library uses underlying C stdio library which means that on Windows local single-byte encoding will be used.

QT Unicode

Internally QT uses UTF-16 encoding. Default conversions from char * (and QString::fromStdString()) assumed to be from local single-byte encoding, not UTF-8 -- QString::fromUtf8() should be used instead.


bfs::path (boost::filesystem::path) uses native platform encoding until being imbued with different locale. It means by default on Windows UTF-16 is used while UTF-8 on Unix-based platforms. boost::locale::generator.generate("") creates UTF-8 environment and should be fed to bfs::path::imbue() on application setup on Windows. boost::iostreams are allowed to take bfs::path instead of string filename (Note: beware of most-vexing parse error, enclose bfs::path argument in additional pair of parentheses while constructing boost::fstream).


Historically OpenMW assumes UTF-8 encoding.

CLI tools

Entry point main(int, char **) on Windows is strongly for local single-byte encoding, no way to pass Unicode. Therefore, wmain(int, wchar_t **) should be ifdefed for this purpose and wchar_t which is UTF-16 should be converted to UTF-8 before passing to any OpenMW interface.