diff options
author | John Fultz <jfultz@wolfram.com> | 2023-07-15 21:24:54 -0500 |
---|---|---|
committer | John Fultz <jfultz@wolfram.com> | 2023-07-16 09:02:22 -0500 |
commit | e588b3c3a1052dfc063c9c058d361347329e7899 (patch) | |
tree | f2b4df04526b071e7cada64c9e14e66ebb07dd3b /quackleio | |
parent | 97b2ebe1b0d2bafb9d870bc9422ee721e08a6657 (diff) |
Make UTF8-encoding of QTextStream work in Qt5 and 6.
QTextStream::setCodec() is no longer a thing in Qt6. Most of
our call are to set the codec to UTF-8, which happens to be the
default encoding in Qt6. So make a macro so this can compile
in both Qt5 and Qt6.
Diffstat (limited to 'quackleio')
-rw-r--r-- | quackleio/flexiblealphabet.cpp | 2 | ||||
-rw-r--r-- | quackleio/gcgio.cpp | 2 | ||||
-rw-r--r-- | quackleio/util.h | 6 |
3 files changed, 8 insertions, 2 deletions
diff --git a/quackleio/flexiblealphabet.cpp b/quackleio/flexiblealphabet.cpp index 011e59b..91d339e 100644 --- a/quackleio/flexiblealphabet.cpp +++ b/quackleio/flexiblealphabet.cpp @@ -44,7 +44,7 @@ bool FlexibleAlphabetParameters::load(const QString &filename) } QTextStream stream(&file); - stream.setCodec(QTextCodec::codecForName("UTF-8")); + SET_QTEXTSTREAM_TO_UTF8(stream); QString line; Quackle::Letter letter = QUACKLE_FIRST_LETTER; diff --git a/quackleio/gcgio.cpp b/quackleio/gcgio.cpp index e2c569d..0cbce9e 100644 --- a/quackleio/gcgio.cpp +++ b/quackleio/gcgio.cpp @@ -333,7 +333,7 @@ bool GCGIO::canRead(QTextStream &stream) const void GCGIO::write(const Quackle::Game &game, QTextStream &stream) { Quackle::PlayerList players = game.players(); - stream.setCodec(QTextCodec::codecForName("UTF-8")); + SET_QTEXTSTREAM_TO_UTF8(stream); stream << "#character-encoding UTF-8" << m_endl; for (Quackle::PlayerList::iterator it = players.begin(); it != players.end(); ++it) { diff --git a/quackleio/util.h b/quackleio/util.h index 19ec469..c186cf6 100644 --- a/quackleio/util.h +++ b/quackleio/util.h @@ -22,6 +22,12 @@ #include <QString> #include <QRegularExpression> +#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) +#define SET_QTEXTSTREAM_TO_UTF8(stream) stream.setCodec(QTextCodec::codecForName("UTF-8")) +#else // QTextStream::setEncoding is gone in Qt6, but streams are UTF8 by default +#define SET_QTEXTSTREAM_TO_UTF8(stream) 0 +#endif + #include <alphabetparameters.h> #include <datamanager.h> #include <uv.h> |