-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Qt6: QTextStream compatibility #120
Conversation
This provides compatibility with the removal of the global ::endl for use with QTextStream; Qt6 requires Qt::endl. It also includes Qt6 specific changes necessary to deal with the replacement of QTextCodec by QStringConverter and the slight changes to the default setup of QTextStream (to UTF-8 with auto-detect of UTF-16). Signed-off-by: John Bowler <[email protected]>
Should be constexpr Signed-off-by: John Bowler <[email protected]>
# 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(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
* is almost certainly the correct behavior because the BOM isn't valid in | ||
* a text stream otherwise. | ||
*/ | ||
#endif | ||
QByteArray contents = stream.readAll().toUtf8(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
- provides compatibility with the removal of the global ::endl for use with QTextStream; Qt6 requires Qt::endl - includes Qt6 specific changes necessary to deal with the replacement of QTextCodec by QStringConverter and the slight changes to the default setup of QTextStream (to UTF-8 with auto-detect of UTF-16) --------- Signed-off-by: John Bowler <[email protected]>
- provides compatibility with the removal of the global ::endl for use with QTextStream; Qt6 requires Qt::endl - includes Qt6 specific changes necessary to deal with the replacement of QTextCodec by QStringConverter and the slight changes to the default setup of QTextStream (to UTF-8 with auto-detect of UTF-16) --------- Signed-off-by: John Bowler <[email protected]>
- provides compatibility with the removal of the global ::endl for use with QTextStream; Qt6 requires Qt::endl - includes Qt6 specific changes necessary to deal with the replacement of QTextCodec by QStringConverter and the slight changes to the default setup of QTextStream (to UTF-8 with auto-detect of UTF-16) --------- Signed-off-by: John Bowler <[email protected]>
- provides compatibility with the removal of the global ::endl for use with QTextStream; Qt6 requires Qt::endl - includes Qt6 specific changes necessary to deal with the replacement of QTextCodec by QStringConverter and the slight changes to the default setup of QTextStream (to UTF-8 with auto-detect of UTF-16) --------- Signed-off-by: John Bowler <[email protected]>
This provides compatibility with the removal of the global ::endl for use with QTextStream; Qt6 requires Qt::endl.
It also includes Qt6 specific changes necessary to deal with the replacement of QTextCodec by QStringConverter and the slight changes to the default setup of QTextStream (to UTF-8 with auto-detect of UTF-16).