From e588b3c3a1052dfc063c9c058d361347329e7899 Mon Sep 17 00:00:00 2001 From: John Fultz Date: Sat, 15 Jul 2023 21:24:54 -0500 Subject: 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. --- quackleio/util.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'quackleio/util.h') 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 #include +#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 #include #include -- cgit v1.2.3