Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions generator/abstractmetabuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@
#include <QtCore/QDebug>
#include <QtCore/QFile>
#include <QtCore/QFileInfo>
#include <QtCore/QTextCodec>
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
# include <QtCore/QTextCodec>
#endif
#include <QtCore/QTextStream>
#include <QtCore/QVariant>

Expand Down Expand Up @@ -402,7 +404,10 @@ bool AbstractMetaBuilder::build()
return false;

QTextStream stream(&file);
stream.setCodec(QTextCodec::codecForName("UTF-8"));
# if QT_VERSION < QT_VERSION_CHECK(6,0,0)
stream.setCodec(QTextCodec::codecForName("UTF-8"));
/* Note required in Qt6: see the same call in asttoxml.cpp */
# endif
QByteArray contents = stream.readAll().toUtf8();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is a QTextStream used here anyway, if the read content is converted back to UTF-8 immediately?
It seems to me the content of the file could be read without the intermediate decoding/encoding step.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe to remove the BOM which would probably mess up the resultant byte array? It also handles UTF-16 correctly in Qt6.

file.close();

Expand Down
17 changes: 15 additions & 2 deletions generator/asttoxml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@

#include <QXmlStreamWriter>
#include <QTextStream>
#include <QTextCodec>
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
# include <QTextCodec>
#endif
#include <QFile>

void astToXML(QString name) {
Expand All @@ -57,7 +59,18 @@ void astToXML(QString name) {
return;

QTextStream stream(&file);
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
stream.setCodec(QTextCodec::codecForName("UTF-8"));
#else
/* NOTE, for Qt6:
*
* stream.setEncoding(QStringConverter::Utf8)
*
* is the default but will be overridden if the UTF-16 BOM is seen. This
* is almost certainly the correct behavior because the BOM isn't valid in
* a text stream otherwise.
*/
#endif
QByteArray contents = stream.readAll().toUtf8();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

file.close();

Expand Down Expand Up @@ -164,7 +177,7 @@ void writeOutClass(QXmlStreamWriter &s, ClassModelItem &item) {
writeOutEnum(s, enumItem);
}

QHash<QString, FunctionModelItem> functionMap = item->functionMap();
QMultiHash<QString, FunctionModelItem> functionMap = item->functionMap();
for (FunctionModelItem funcItem : functionMap.values()) {
writeOutFunction(s, funcItem);
}
Expand Down
24 changes: 24 additions & 0 deletions generator/typesystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
#include <QtCore/QMap>
#include <QDebug>

/* BEGIN: Qt6 compatibility. The following can removed when versions of Qt
* prior to 5.14 are no longer supported.
*/
/* QString::SkipEmptyParts was replicated in Qt::SplitBehavior in 15.4 and the
* QString original deprecated then it was removed in Qt6. This provides
* forward compatibility with Qt6 for versions of Qt prior to 15.4:
Expand All @@ -58,6 +61,27 @@
};
#endif

/* Global endl (::endl) is used extensively in the generator .cpp files. This
* was supported by Qt until Qt6. In Qt5.14 Qt::endl was added in anticipation
* of the Qt6 change and the use of global endl could be avoided (it does not
* seem to have been explicitly deprecated). This gives backward compatibility
* for global endl in Qt6 (not Qt5, where global endl was still available).
*
* Note that 'constexpr' is available in Qt6 because Qt6 requires C++17;
* constexpr was introduced in C++11. Likewise for decltype. Qt::endl is a
* function so ::endl is a pointer to the function and the implicit conversion
* is used; this is to cause an compiler error in the future if the base type
* of Qt::endl changes.
*
* When versions of Qt older than 5.14 are no longer supported this can be
* removed however all the 'endl' references in the code will need to be
* changed to Qt::endl.
*/
#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
static const constexpr decltype (Qt::endl) *endl = Qt::endl;
#endif
/* END: Qt compatibility. */

class Indentor;

class AbstractMetaType;
Expand Down