Skip to content

UI: Fix Qt6 build issues#4318

Merged
jp9000 merged 5 commits into
obsproject:masterfrom
RytoEX:qt6-fixes
Mar 10, 2021
Merged

UI: Fix Qt6 build issues#4318
jp9000 merged 5 commits into
obsproject:masterfrom
RytoEX:qt6-fixes

Conversation

@RytoEX

@RytoEX RytoEX commented Mar 9, 2021

Copy link
Copy Markdown
Member

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 #if checks or prevent warnings. Descriptions are included in the individual commits, but they are also provided here for convenience.

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

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

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

  4. UI: Explicitly include QFile
    Explicitly include QFile to prevent a build failure with VS2019 and Qt6.

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

  • Bug fix (non-breaking change which fixes an issue)
  • Code cleanup (non-breaking change which makes code smaller or more readable)

Checklist:

  • My code has been run through clang-format.
  • I have read the contributing document.
  • My code is not on the master branch.
  • The code has been tested.
  • All commit messages are properly formatted and commits squashed where appropriate.
  • I have included updates to all appropriate documentation.

RytoEX added 5 commits March 9, 2021 09:16
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
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.
@RytoEX RytoEX added kind/bug Categorizes issue or PR as related to a bug. kind/cleanup Non-breaking change which makes code smaller or more readable labels Mar 9, 2021
@jp9000
jp9000 merged commit fc6e085 into obsproject:master Mar 10, 2021
@RytoEX
RytoEX deleted the qt6-fixes branch March 10, 2021 08:35
@RytoEX RytoEX added this to the OBS Studio 27.0 milestone Mar 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Categorizes issue or PR as related to a bug. kind/cleanup Non-breaking change which makes code smaller or more readable

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants