Fix Qt6 building (#4393)

This commit is contained in:
pajlada 2023-02-19 20:19:18 +01:00 committed by GitHub
parent d3499e814e
commit c95a65c153
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 114 additions and 37 deletions

View file

@ -15,6 +15,7 @@ concurrency:
env: env:
C2_ENABLE_LTO: ${{ github.ref == 'refs/heads/master' }} C2_ENABLE_LTO: ${{ github.ref == 'refs/heads/master' }}
CHATTERINO_REQUIRE_CLEAN_GIT: On CHATTERINO_REQUIRE_CLEAN_GIT: On
C2_BUILD_WITH_QT6: Off
jobs: jobs:
build: build:
@ -39,6 +40,11 @@ jobs:
qt-version: 5.15.2 qt-version: 5.15.2
pch: true pch: true
force-lto: false force-lto: false
# Ubuntu 22.04, Qt 6.2.4
- os: ubuntu-22.04
qt-version: 6.2.4
pch: false
force-lto: false
# Test for disabling Precompiled Headers & enabling link-time optimization # Test for disabling Precompiled Headers & enabling link-time optimization
- os: ubuntu-22.04 - os: ubuntu-22.04
qt-version: 5.15.2 qt-version: 5.15.2
@ -73,18 +79,34 @@ jobs:
echo "vs_version=2022" >> "$GITHUB_ENV" echo "vs_version=2022" >> "$GITHUB_ENV"
shell: bash shell: bash
- name: Set BUILD_WITH_QT6
if: startsWith(matrix.qt-version, '6.')
run: |
echo "C2_BUILD_WITH_QT6=ON" >> "$GITHUB_ENV"
shell: bash
- uses: actions/checkout@v3 - uses: actions/checkout@v3
with: with:
submodules: recursive submodules: recursive
fetch-depth: 0 # allows for tags access fetch-depth: 0 # allows for tags access
- name: Install Qt - name: Install Qt5
if: startsWith(matrix.qt-version, '5.')
uses: jurplel/install-qt-action@v3.0.0 uses: jurplel/install-qt-action@v3.0.0
with: with:
cache: true cache: true
cache-key-prefix: ${{ runner.os }}-QtCache-${{ matrix.qt-version }}-v2 cache-key-prefix: ${{ runner.os }}-QtCache-${{ matrix.qt-version }}-v2
version: ${{ matrix.qt-version }} version: ${{ matrix.qt-version }}
- name: Install Qt6
if: startsWith(matrix.qt-version, '6.')
uses: jurplel/install-qt-action@v3.0.0
with:
cache: true
cache-key-prefix: ${{ runner.os }}-QtCache-${{ matrix.qt-version }}-v2
modules: qt5compat
version: ${{ matrix.qt-version }}
# WINDOWS # WINDOWS
- name: Cache conan packages part 1 - name: Cache conan packages part 1
if: startsWith(matrix.os, 'windows') if: startsWith(matrix.os, 'windows')
@ -131,6 +153,7 @@ jobs:
-DCMAKE_TOOLCHAIN_FILE="conan_toolchain.cmake" ` -DCMAKE_TOOLCHAIN_FILE="conan_toolchain.cmake" `
-DBUILD_WITH_CRASHPAD="$Env:C2_ENABLE_CRASHPAD" ` -DBUILD_WITH_CRASHPAD="$Env:C2_ENABLE_CRASHPAD" `
-DCHATTERINO_LTO="$Env:C2_ENABLE_LTO" ` -DCHATTERINO_LTO="$Env:C2_ENABLE_LTO" `
-DBUILD_WITH_QT6="$Env:C2_BUILD_WITH_QT6" `
.. ..
set cl=/MP set cl=/MP
nmake /S /NOLOGO nmake /S /NOLOGO
@ -216,6 +239,7 @@ jobs:
-DUSE_PRECOMPILED_HEADERS=${{ matrix.pch }} \ -DUSE_PRECOMPILED_HEADERS=${{ matrix.pch }} \
-DCMAKE_EXPORT_COMPILE_COMMANDS=On \ -DCMAKE_EXPORT_COMPILE_COMMANDS=On \
-DCHATTERINO_LTO="$C2_ENABLE_LTO" \ -DCHATTERINO_LTO="$C2_ENABLE_LTO" \
-DBUILD_WITH_QT6="$C2_BUILD_WITH_QT6" \
.. ..
make -j"$(nproc)" make -j"$(nproc)"
shell: bash shell: bash
@ -284,6 +308,7 @@ jobs:
-DOPENSSL_ROOT_DIR=/usr/local/opt/openssl \ -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl \
-DUSE_PRECOMPILED_HEADERS=${{ matrix.pch }} \ -DUSE_PRECOMPILED_HEADERS=${{ matrix.pch }} \
-DCHATTERINO_LTO="$C2_ENABLE_LTO" \ -DCHATTERINO_LTO="$C2_ENABLE_LTO" \
-DBUILD_WITH_QT6="$C2_BUILD_WITH_QT6" \
.. ..
make -j"$(sysctl -n hw.logicalcpu)" make -j"$(sysctl -n hw.logicalcpu)"
shell: bash shell: bash

View file

@ -2,6 +2,7 @@
## Unversioned ## Unversioned
- Dev: Add capability to build Chatterino with Qt6. (#4393)
- Dev: Fix homebrew update action. (#4394) - Dev: Fix homebrew update action. (#4394)
## 2.4.1 ## 2.4.1

View file

@ -58,6 +58,13 @@ find_package(Qt${MAJOR_QT_VERSION} REQUIRED
Concurrent Concurrent
) )
if (BUILD_WITH_QT6)
find_package(Qt${MAJOR_QT_VERSION} REQUIRED
COMPONENTS
Core5Compat
)
endif ()
message(STATUS "Qt version: ${Qt${MAJOR_QT_VERSION}_VERSION}") message(STATUS "Qt version: ${Qt${MAJOR_QT_VERSION}_VERSION}")
if (WIN32) if (WIN32)

View file

@ -620,6 +620,14 @@ target_link_libraries(${LIBRARY_PROJECT}
LRUCache LRUCache
MagicEnum MagicEnum
) )
if (BUILD_WITH_QT6)
target_link_libraries(${LIBRARY_PROJECT}
PUBLIC
Qt${MAJOR_QT_VERSION}::Core5Compat
)
endif ()
if (BUILD_WITH_QTKEYCHAIN) if (BUILD_WITH_QTKEYCHAIN)
target_link_libraries(${LIBRARY_PROJECT} target_link_libraries(${LIBRARY_PROJECT}
PUBLIC PUBLIC

View file

@ -105,7 +105,6 @@
# include <QThreadPool> # include <QThreadPool>
# include <QTime> # include <QTime>
# include <QTimer> # include <QTimer>
# include <QtWidgets/QAction>
# include <QtWidgets/QApplication> # include <QtWidgets/QApplication>
# include <QtWidgets/QButtonGroup> # include <QtWidgets/QButtonGroup>
# include <QtWidgets/QDialog> # include <QtWidgets/QDialog>

View file

@ -16,7 +16,12 @@ namespace {
QFile file(":/tlds.txt"); QFile file(":/tlds.txt");
file.open(QFile::ReadOnly); file.open(QFile::ReadOnly);
QTextStream stream(&file); QTextStream stream(&file);
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
// Default encoding of QTextStream is already UTF-8, at least in Qt6
#else
stream.setCodec("UTF-8"); stream.setCodec("UTF-8");
#endif
int safetyMax = 20000; int safetyMax = 20000;
QSet<QString> set; QSet<QString> set;

View file

@ -3191,7 +3191,8 @@ QString CommandController::execCommand(const QString &textNoEmoji,
} }
} }
auto maxSpaces = std::min(this->maxSpaces_, words.length() - 1); // We have checks to ensure words cannot be empty, so this can never wrap around
auto maxSpaces = std::min(this->maxSpaces_, (qsizetype)words.length() - 1);
for (int i = 0; i < maxSpaces; ++i) for (int i = 0; i < maxSpaces; ++i)
{ {
commandName += ' ' + words[i + 1]; commandName += ' ' + words[i + 1];

View file

@ -62,7 +62,7 @@ private:
// User-created commands // User-created commands
QMap<QString, Command> userCommands_; QMap<QString, Command> userCommands_;
int maxSpaces_ = 0; qsizetype maxSpaces_ = 0;
std::shared_ptr<pajlada::Settings::SettingManager> sm_; std::shared_ptr<pajlada::Settings::SettingManager> sm_;
// Because the setting manager is not initialized until the initialize // Because the setting manager is not initialized until the initialize

View file

@ -7,6 +7,7 @@
#define MINIAUDIO_IMPLEMENTATION #define MINIAUDIO_IMPLEMENTATION
#include <miniaudio.h> #include <miniaudio.h>
#include <QFile>
#include <limits> #include <limits>
#include <memory> #include <memory>

View file

@ -1,5 +1,6 @@
#include "providers/bttv/liveupdates/BttvLiveUpdateSubscription.hpp" #include "providers/bttv/liveupdates/BttvLiveUpdateSubscription.hpp"
#include <QDebug>
#include <QJsonDocument> #include <QJsonDocument>
namespace chatterino { namespace chatterino {

View file

@ -94,7 +94,8 @@ void IrcServer::initializeConnectionSignals(IrcConnection *connection,
QObject::connect(connection, &Communi::IrcConnection::nickNameRequired, QObject::connect(connection, &Communi::IrcConnection::nickNameRequired,
this, [](const QString &reserved, QString *result) { this, [](const QString &reserved, QString *result) {
*result = reserved + (std::rand() % 100); *result = QString("%1%2").arg(
reserved, QString::number(std::rand() % 100));
}); });
QObject::connect(connection, &Communi::IrcConnection::noticeMessageReceived, QObject::connect(connection, &Communi::IrcConnection::noticeMessageReceived,

View file

@ -325,7 +325,7 @@ std::shared_ptr<Channel> TwitchIrcServer::getChannelOrEmptyByID(
continue; continue;
if (twitchChannel->roomId() == channelId && if (twitchChannel->roomId() == channelId &&
twitchChannel->getName().splitRef(":").size() < 3) twitchChannel->getName().count(':') < 2)
{ {
return twitchChannel; return twitchChannel;
} }

View file

@ -821,14 +821,14 @@ void TwitchMessageBuilder::runIgnoreReplaces(
}; };
auto addReplEmotes = [&twitchEmotes](const IgnorePhrase &phrase, auto addReplEmotes = [&twitchEmotes](const IgnorePhrase &phrase,
const QStringRef &midrepl, const auto &midrepl,
int startIndex) mutable { int startIndex) mutable {
if (!phrase.containsEmote()) if (!phrase.containsEmote())
{ {
return; return;
} }
QVector<QStringRef> words = midrepl.split(' '); auto words = midrepl.split(' ');
int pos = 0; int pos = 0;
for (const auto &word : words) for (const auto &word : words)
{ {
@ -843,7 +843,7 @@ void TwitchMessageBuilder::runIgnoreReplaces(
} }
twitchEmotes.push_back(TwitchEmoteOccurrence{ twitchEmotes.push_back(TwitchEmoteOccurrence{
startIndex + pos, startIndex + pos,
startIndex + pos + emote.first.string.length(), startIndex + pos + (int)emote.first.string.length(),
emote.second, emote.second,
emote.first, emote.first,
}); });
@ -904,8 +904,13 @@ void TwitchMessageBuilder::runIgnoreReplaces(
shiftIndicesAfter(from + len, midsize - len); shiftIndicesAfter(from + len, midsize - len);
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
auto midExtendedRef =
QStringView{this->originalMessage_}.mid(pos1, pos2 - pos1);
#else
auto midExtendedRef = auto midExtendedRef =
this->originalMessage_.midRef(pos1, pos2 - pos1); this->originalMessage_.midRef(pos1, pos2 - pos1);
#endif
for (auto &tup : vret) for (auto &tup : vret)
{ {
@ -969,8 +974,13 @@ void TwitchMessageBuilder::runIgnoreReplaces(
shiftIndicesAfter(from + len, replacesize - len); shiftIndicesAfter(from + len, replacesize - len);
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
auto midExtendedRef =
QStringView{this->originalMessage_}.mid(pos1, pos2 - pos1);
#else
auto midExtendedRef = auto midExtendedRef =
this->originalMessage_.midRef(pos1, pos2 - pos1); this->originalMessage_.midRef(pos1, pos2 - pos1);
#endif
for (auto &tup : vret) for (auto &tup : vret)
{ {

View file

@ -174,6 +174,12 @@ QString localizeNumbers(unsigned int number)
return locale.toString(number); return locale.toString(number);
} }
QString localizeNumbers(qsizetype number)
{
QLocale locale;
return locale.toString(number);
}
QString kFormatNumbers(const int &number) QString kFormatNumbers(const int &number)
{ {
return QString("%1K").arg(number / 1000); return QString("%1K").arg(number / 1000);

View file

@ -74,6 +74,7 @@ QString shortenString(const QString &str, unsigned maxWidth = 50);
QString localizeNumbers(const int &number); QString localizeNumbers(const int &number);
QString localizeNumbers(unsigned int number); QString localizeNumbers(unsigned int number);
QString localizeNumbers(qsizetype number);
QString kFormatNumbers(const int &number); QString kFormatNumbers(const int &number);

View file

@ -641,8 +641,8 @@ void Notebook::performLayout(bool animated)
bool isLastColumn = col == columnCount - 1; bool isLastColumn = col == columnCount - 1;
auto largestWidth = 0; auto largestWidth = 0;
int tabStart = col * tabsPerColumn; int tabStart = col * tabsPerColumn;
int tabEnd = int tabEnd = std::min((col + 1) * tabsPerColumn,
std::min((col + 1) * tabsPerColumn, this->items_.size()); (int)this->items_.size());
for (int i = tabStart; i < tabEnd; i++) for (int i = tabStart; i < tabEnd; i++)
{ {
@ -743,8 +743,8 @@ void Notebook::performLayout(bool animated)
bool isLastColumn = col == columnCount - 1; bool isLastColumn = col == columnCount - 1;
auto largestWidth = 0; auto largestWidth = 0;
int tabStart = col * tabsPerColumn; int tabStart = col * tabsPerColumn;
int tabEnd = int tabEnd = std::min((col + 1) * tabsPerColumn,
std::min((col + 1) * tabsPerColumn, this->items_.size()); (int)this->items_.size());
for (int i = tabStart; i < tabEnd; i++) for (int i = tabStart; i < tabEnd; i++)
{ {

View file

@ -22,6 +22,7 @@
#include "widgets/settingspages/NotificationPage.hpp" #include "widgets/settingspages/NotificationPage.hpp"
#include <QDialogButtonBox> #include <QDialogButtonBox>
#include <QFile>
#include <QLineEdit> #include <QLineEdit>
namespace chatterino { namespace chatterino {

View file

@ -62,7 +62,11 @@ QString ResizingTextEdit::textUnderCursor(bool *hadSpace) const
auto textUpToCursor = currentText.left(tc.selectionStart()); auto textUpToCursor = currentText.left(tc.selectionStart());
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
auto words = QStringView{textUpToCursor}.split(' ');
#else
auto words = textUpToCursor.splitRef(' '); auto words = textUpToCursor.splitRef(' ');
#endif
if (words.size() == 0) if (words.size() == 0)
{ {
return QString(); return QString();

View file

@ -54,7 +54,7 @@ void SettingsDialogTab::paintEvent(QPaintEvent *)
QPainter painter(this); QPainter painter(this);
QStyleOption opt; QStyleOption opt;
opt.init(this); opt.initFrom(this);
this->style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter, this); this->style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter, this);

View file

@ -8,6 +8,7 @@
#include "widgets/BasePopup.hpp" #include "widgets/BasePopup.hpp"
#include "widgets/helper/SignalLabel.hpp" #include "widgets/helper/SignalLabel.hpp"
#include <QFile>
#include <QFormLayout> #include <QFormLayout>
#include <QGroupBox> #include <QGroupBox>
#include <QLabel> #include <QLabel>
@ -144,7 +145,11 @@ AboutPage::AboutPage()
contributorsFile.open(QFile::ReadOnly); contributorsFile.open(QFile::ReadOnly);
QTextStream stream(&contributorsFile); QTextStream stream(&contributorsFile);
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
// Default encoding of QTextStream is already UTF-8
#else
stream.setCodec("UTF-8"); stream.setCodec("UTF-8");
#endif
QString line; QString line;

View file

@ -113,33 +113,34 @@ ModerationPage::ModerationPage()
auto logsPathSizeLabel = logs.emplace<QLabel>(); auto logsPathSizeLabel = logs.emplace<QLabel>();
logsPathSizeLabel->setText(QtConcurrent::run([] { logsPathSizeLabel->setText(QtConcurrent::run([] {
return fetchLogDirectorySize(); return fetchLogDirectorySize();
})); }).result());
// Select event // Select event
QObject::connect(selectDir.getElement(), &QPushButton::clicked, this, QObject::connect(
selectDir.getElement(), &QPushButton::clicked, this,
[this, logsPathSizeLabel]() mutable { [this, logsPathSizeLabel]() mutable {
auto dirName = auto dirName = QFileDialog::getExistingDirectory(this);
QFileDialog::getExistingDirectory(this);
getSettings()->logPath = dirName; getSettings()->logPath = dirName;
// Refresh: Show how big (size-wise) the logs are // Refresh: Show how big (size-wise) the logs are
logsPathSizeLabel->setText(QtConcurrent::run([] { logsPathSizeLabel->setText(QtConcurrent::run([] {
return fetchLogDirectorySize(); return fetchLogDirectorySize();
})); }).result());
}); });
buttons->addSpacing(16); buttons->addSpacing(16);
// Reset custom logpath // Reset custom logpath
QObject::connect(resetDir.getElement(), &QPushButton::clicked, this, QObject::connect(
resetDir.getElement(), &QPushButton::clicked, this,
[logsPathSizeLabel]() mutable { [logsPathSizeLabel]() mutable {
getSettings()->logPath = ""; getSettings()->logPath = "";
// Refresh: Show how big (size-wise) the logs are // Refresh: Show how big (size-wise) the logs are
logsPathSizeLabel->setText(QtConcurrent::run([] { logsPathSizeLabel->setText(QtConcurrent::run([] {
return fetchLogDirectorySize(); return fetchLogDirectorySize();
})); }).result());
}); });
QCheckBox *onlyLogListedChannels = QCheckBox *onlyLogListedChannels =

View file

@ -699,7 +699,7 @@ void SplitInput::updateCompletionPopup()
return; return;
} }
for (int i = clamp(position, 0, text.length() - 1); i >= 0; i--) for (int i = clamp(position, 0, (int)text.length() - 1); i >= 0; i--)
{ {
if (text[i] == ' ') if (text[i] == ' ')
{ {
@ -766,7 +766,7 @@ void SplitInput::showCompletionPopup(const QString &text, bool emoteCompletion)
popup->updateUsers(text, this->split_->getChannel()); popup->updateUsers(text, this->split_->getChannel());
} }
auto pos = this->mapToGlobal({0, 0}) - QPoint(0, popup->height()) + auto pos = this->mapToGlobal(QPoint{0, 0}) - QPoint(0, popup->height()) +
QPoint((this->width() - popup->width()) / 2, 0); QPoint((this->width() - popup->width()) / 2, 0);
popup->move(pos); popup->move(pos);
@ -789,7 +789,7 @@ void SplitInput::insertCompletionText(const QString &input_) const
auto text = edit.toPlainText(); auto text = edit.toPlainText();
auto position = edit.textCursor().position() - 1; auto position = edit.textCursor().position() - 1;
for (int i = clamp(position, 0, text.length() - 1); i >= 0; i--) for (int i = clamp(position, 0, (int)text.length() - 1); i >= 0; i--)
{ {
bool done = false; bool done = false;
if (text[i] == ':') if (text[i] == ':')