Skip to content
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

Merged
merged 2 commits into from
Oct 5, 2023
Merged

Qt6: QTextStream compatibility #120

merged 2 commits into from
Oct 5, 2023

Conversation

jbowler
Copy link
Contributor

@jbowler jbowler commented Oct 5, 2023

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).

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]>
@mrbean-bremen mrbean-bremen merged commit 1770cb3 into MeVisLab:qt6 Oct 5, 2023
11 checks passed
@jbowler jbowler deleted the pull-request-120 branch October 5, 2023 22:37
# 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.

* 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.

mrbean-bremen pushed a commit to mrbean-bremen/pythonqt that referenced this pull request Oct 29, 2023

- 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]>
mrbean-bremen pushed a commit that referenced this pull request Oct 29, 2023

- 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]>
mrbean-bremen pushed a commit that referenced this pull request Nov 1, 2023

- 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]>
mrbean-bremen pushed a commit that referenced this pull request Nov 2, 2023

- 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants