Skip to content

Instantly share code, notes, and snippets.

@jsm222
Created August 11, 2026 21:02
Show Gist options
  • Select an option

  • Save jsm222/9b602088f233ccfd24bf173d30d3879f to your computer and use it in GitHub Desktop.

Select an option

Save jsm222/9b602088f233ccfd24bf173d30d3879f to your computer and use it in GitHub Desktop.
include <locale.h>
#include <cstring>
#include <QString>
#include <QDebug>
#include <langinfo.h>
int main() {
setlocale(LC_ALL, "");
// std::string's SSO usually saves this the need to allocate:
const std::string oldEncoding = nl_langinfo(CODESET);
if (!Q_LIKELY(qstricmp(oldEncoding.data(), "UTF-8") == 0
|| qstricmp(oldEncoding.data(), "utf8") == 0)) {
qDebug() << oldEncoding.data();
const QByteArray oldLocale = setlocale(LC_ALL, nullptr);
QByteArray newLocale;
bool warnOnOverride = true;
}
return 0;
}
//c++ t.cpp -I /usr/local/include/qt6/QtCore -I /usr/local/include/qt6/ -L /usr/local/lib/qt6/ -lQt6Core -o localetest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment