Update qtcommon.h

This commit is contained in:
恍兮惚兮 2024-04-21 19:14:52 +08:00
parent 7d968b2f18
commit 799a90e09c

View File

@ -29,7 +29,13 @@ constexpr auto WINDOW = u8"Window";
struct Settings : QSettings { Settings(QObject* parent = nullptr) : QSettings(CONFIG_FILE, QSettings::IniFormat, parent) {} };
struct QTextFile : QFile { QTextFile(QString name, QIODevice::OpenMode mode) : QFile(name) { open(mode | QIODevice::Text); } };
struct Localizer { Localizer() { Localize(); } };
inline std::wstring S(const QString& s) { return { s.toStdWString() }; }
inline std::wstring S(const QString& s) {
//s.toStdWString will crash. unknown why.
std::wstring ws;
ws.resize(s.size()+1);
s.toWCharArray(ws.data());
return ws;
}
inline QString S(const std::string& s) { return QString::fromStdString(s); }
inline QString S(const std::wstring& s) { return QString::fromStdWString(s); }
// TODO: allow paired surrogates