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 | |
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.
-rw-r--r-- | encodeleaves/encodeleaves.cpp | 2 | ||||
-rw-r--r-- | makegaddag/makegaddag.cpp | 2 | ||||
-rw-r--r-- | makeminidawg/makeminidawgmain.cpp | 6 | ||||
-rw-r--r-- | quacker/graphicalreporter.cpp | 2 | ||||
-rw-r--r-- | quacker/letterbox.cpp | 10 | ||||
-rw-r--r-- | quacker/lexicondialog.cpp | 2 | ||||
-rw-r--r-- | quacker/lister.cpp | 5 | ||||
-rw-r--r-- | quacker/quacker.cpp | 8 | ||||
-rw-r--r-- | quackleio/flexiblealphabet.cpp | 2 | ||||
-rw-r--r-- | quackleio/gcgio.cpp | 2 | ||||
-rw-r--r-- | quackleio/util.h | 6 |
11 files changed, 27 insertions, 20 deletions
diff --git a/encodeleaves/encodeleaves.cpp b/encodeleaves/encodeleaves.cpp index 0755955..bba8327 100644 --- a/encodeleaves/encodeleaves.cpp +++ b/encodeleaves/encodeleaves.cpp @@ -64,7 +64,7 @@ int main(int argc, char **argv) { } QTextStream stream(&file); - stream.setCodec(QTextCodec::codecForName("UTF-8")); + SET_QTEXTSTREAM_TO_UTF8(stream); ofstream out("encoded"); diff --git a/makegaddag/makegaddag.cpp b/makegaddag/makegaddag.cpp index b9d3852..5d63695 100644 --- a/makegaddag/makegaddag.cpp +++ b/makegaddag/makegaddag.cpp @@ -78,7 +78,7 @@ int main(int argc, char **argv) } QTextStream stream(&file); - stream.setCodec(QTextCodec::codecForName("UTF-8")); + SET_QTEXTSTREAM_TO_UTF8(stream); while (!stream.atEnd()) { diff --git a/makeminidawg/makeminidawgmain.cpp b/makeminidawg/makeminidawgmain.cpp index ade6c89..2096899 100644 --- a/makeminidawg/makeminidawgmain.cpp +++ b/makeminidawg/makeminidawgmain.cpp @@ -60,7 +60,7 @@ int main(int argc, char **argv) } QTextStream smallerStream(&smallerDict); - smallerStream.setCodec(QTextCodec::codecForName("UTF-8")); + SET_QTEXTSTREAM_TO_UTF8(smallerStream); while (!smallerStream.atEnd()) { @@ -85,7 +85,7 @@ int main(int argc, char **argv) } QTextStream playabilityStream(&playability); - playabilityStream.setCodec(QTextCodec::codecForName("UTF-8")); + SET_QTEXTSTREAM_TO_UTF8(playabilityStream); while (!playabilityStream.atEnd()) { @@ -112,7 +112,7 @@ int main(int argc, char **argv) } QTextStream stream(&file); - stream.setCodec(QTextCodec::codecForName("UTF-8")); + SET_QTEXTSTREAM_TO_UTF8(stream); while (!stream.atEnd()) { diff --git a/quacker/graphicalreporter.cpp b/quacker/graphicalreporter.cpp index 86b539d..4c9fa43 100644 --- a/quacker/graphicalreporter.cpp +++ b/quacker/graphicalreporter.cpp @@ -229,6 +229,6 @@ void GraphicalReporter::openIndex() m_indexStream.setDevice(&m_indexFile); } - m_indexStream.setCodec(QTextCodec::codecForName("UTF-8")); + SET_QTEXTSTREAM_TO_UTF8(m_indexStream); } diff --git a/quacker/letterbox.cpp b/quacker/letterbox.cpp index aeed7af..6921dca 100644 --- a/quacker/letterbox.cpp +++ b/quacker/letterbox.cpp @@ -232,7 +232,7 @@ void Letterbox::loadFile() QTextStream stream(&file); QString line; - stream.setCodec(QTextCodec::codecForName("UTF-8")); + SET_QTEXTSTREAM_TO_UTF8(stream); m_initializationChuu = true; @@ -522,7 +522,7 @@ void Letterbox::outputResults() } QTextStream stream(&file); - stream.setCodec(QTextCodec::codecForName("UTF-8")); + SET_QTEXTSTREAM_TO_UTF8(stream); if (m_numberIterator < m_clueResults.count()) stream << "\" Resume: " << m_numberIterator << "\n"; @@ -558,7 +558,7 @@ void Letterbox::outputResults() } QTextStream stream(&missesFile); - stream.setCodec(QTextCodec::codecForName("UTF-8")); + SET_QTEXTSTREAM_TO_UTF8(stream); for (const auto& it : m_clueResults) { @@ -924,7 +924,7 @@ void Letterbox::print() setModified(wasModified); QTextStream stream(&file); - stream.setCodec(QTextCodec::codecForName("UTF-8")); + SET_QTEXTSTREAM_TO_UTF8(stream); stream << printer.html() << "\n"; file.close(); @@ -955,7 +955,7 @@ void Letterbox::printStudy() jumpTo(m_clueResults.size() - 1); QTextStream stream(&file); - stream.setCodec(QTextCodec::codecForName("UTF-8")); + SET_QTEXTSTREAM_TO_UTF8(stream); stream << generateStudySheet(m_answers.begin(), m_answers.end()) << "\n"; file.close(); diff --git a/quacker/lexicondialog.cpp b/quacker/lexicondialog.cpp index 4f6d35d..88e86b1 100644 --- a/quacker/lexicondialog.cpp +++ b/quacker/lexicondialog.cpp @@ -218,7 +218,7 @@ void LexiconDialog::addWordsFromTextFile(const QString &textFile) return; QTextStream stream(&file); - stream.setCodec("UTF-8"); + SET_QTEXTSTREAM_TO_UTF8(stream); QString word; while (!stream.atEnd()) { diff --git a/quacker/lister.cpp b/quacker/lister.cpp index c3a4ea9..644dd90 100644 --- a/quacker/lister.cpp +++ b/quacker/lister.cpp @@ -22,6 +22,7 @@ using namespace std; #include <QtWidgets> #include <quackleio/dictfactory.h> +#include <quackleio/util.h> #include "lister.h" #include "customqsettings.h" @@ -233,7 +234,7 @@ void ListerDialog::openFile() if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { QTextStream stream(&file); - stream.setCodec(QTextCodec::codecForName("UTF-8")); + SET_QTEXTSTREAM_TO_UTF8(stream); QString line; while (!stream.atEnd()) { @@ -429,7 +430,7 @@ QString ListerDialog::writeList(bool alphagrams) } QTextStream stream(&file); - stream.setCodec(QTextCodec::codecForName("UTF-8")); + SET_QTEXTSTREAM_TO_UTF8(stream); QMap<QString, Dict::WordList> map(anagramMap()); diff --git a/quacker/quacker.cpp b/quacker/quacker.cpp index e7cc401..a244586 100644 --- a/quacker/quacker.cpp +++ b/quacker/quacker.cpp @@ -1335,7 +1335,7 @@ void TopLevel::reportAs(Quackle::ComputerPlayer *player) Quackle::ComputerPlayer *clone = player->clone(); QTextStream stream(&file); - stream.setCodec(QTextCodec::codecForName("UTF-8")); + SET_QTEXTSTREAM_TO_UTF8(stream); QuackleIO::StreamingReporter::reportGame(*m_game, clone, stream); delete clone; } @@ -2100,7 +2100,7 @@ void TopLevel::writeAsciiToFile(const QString &text, const QString &filename) } QTextStream stream(&file); - stream.setCodec(QTextCodec::codecForName("UTF-8")); + SET_QTEXTSTREAM_TO_UTF8(stream); stream << text << "\n"; file.close(); @@ -2126,7 +2126,7 @@ void TopLevel::print() } QTextStream stream(&file); - stream.setCodec(QTextCodec::codecForName("UTF-8")); + SET_QTEXTSTREAM_TO_UTF8(stream); //stream << printer.html() << "\n"; file.close(); @@ -2160,7 +2160,7 @@ void TopLevel::about() if (file) { QTextStream strm(file); - strm.setCodec("UTF-8"); + SET_QTEXTSTREAM_TO_UTF8(strm); QString line = strm.readLine(); while (!line.isNull()) { 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> |