UI: Fix Qt6 build issues#4318
Merged
Merged
Conversation
Make building against either Qt5 or Qt6 easier by checking the Qt version used and loading the appropriate Qt Network DLL.
Our QT_UTF8(str) macro uses QString::fromUtf8(str) with no size argument. In Qt5, QString::fromUtf8 uses a default value of -1 for the size arg. If size is -1, it is taken to be strlen(str). In Qt6, QString::fromUtf8 doesn't use a default value for the size arg, but has the same behavior if you manually specify -1 for the size. Let's manually specify -1 to maintain the same behavior between Qt5 and Qt6. https://doc.qt.io/qt-5/qstring.html#fromUtf8 https://doc.qt.io/qt-6/qstring.html#fromUtf8
In Qt6, QTextStream::setCodec has been replaced by QTextStream::setEncoding. However, all text is assumed to be UTF-8, so we don't need to specify UTF-8 in Qt6. https://doc.qt.io/qt-5/qtextstream.html#setCodec-1 https://doc.qt.io/qt-6/qtextstream.html#setEncoding
Explicitly include QFile to prevent a build failure with VS2019 and Qt6.
Qt6 enables Qt::AA_UseHighDpiPixmaps by default and will emit a warning if you try to enable it. To prevent the warning, only set this on Qt5.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fix some issues with Qt6 compatibility. Strictly speaking, only the first and fourth commits are necessary. I consider the others to be cleanups as they either simplify
#ifchecks or prevent warnings. Descriptions are included in the individual commits, but they are also provided here for convenience.UI: Force plugins to use version appropriate Qt Network
Make building against either Qt5 or Qt6 easier by checking the Qt version used and loading the appropriate Qt Network DLL.
UI: Set default string size arg for QT_UTF8 / QString::fromUtf8
Our QT_UTF8(str) macro uses QString::fromUtf8(str) with no size argument. In Qt5, QString::fromUtf8 uses a default value of -1 for the size arg. If size is -1, it is taken to be strlen(str). In Qt6, QString::fromUtf8 doesn't use a default value for the size arg, but has the same behavior if you manually specify -1 for the size. Let's manually specify -1 to maintain the same behavior between Qt5 and Qt6.
https://doc.qt.io/qt-5/qstring.html#fromUtf8
https://doc.qt.io/qt-6/qstring.html#fromUtf8
UI: Don't use QTextStream::setCodec in Qt6
In Qt6, QTextStream::setCodec has been replaced by QTextStream::setEncoding. However, all text is assumed to be UTF-8, so we don't need to specify UTF-8 in Qt6.
https://doc.qt.io/qt-5/qtextstream.html#setCodec-1
https://doc.qt.io/qt-6/qtextstream.html#setEncoding
UI: Explicitly include QFile
Explicitly include QFile to prevent a build failure with VS2019 and Qt6.
UI: Set Qt::AA_UseHighDpiPixmaps only on Qt5
Qt6 enables Qt::AA_UseHighDpiPixmaps by default and will emit a warning if you try to enable it. To prevent the warning, only set this on Qt5.
Motivation and Context
Being able to build on Qt6 now will make things easier whenever we move to Qt6.
How Has This Been Tested?
I've compiled and run OBS with Qt6 on Windows 10 64-bit. I've also verified that compiling against Qt5 still works on Windows 10 64-bit.
Please note that compiling with Qt6 requires additional CMake changes. Those changes will be in a separate PR because they're disruptive and not compatible with Qt5, and perhaps they're better suited for a separate branch.
Types of changes
Checklist: