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

Fix Qt6 building #4393

Merged
merged 26 commits into from
Feb 19, 2023
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
9303944
Add Qt Core5Compat dependency if building with Qt6
pajlada Feb 19, 2023
8401fbe
Add specialization to `localizeNumber` that accepts a `qsizetype`
pajlada Feb 19, 2023
6b3a2c2
Add missing `QFile` include to `SoundController.cpp`
pajlada Feb 19, 2023
33963a0
Add missing `QFile` include to `SettingsDialog.cpp`
pajlada Feb 19, 2023
a1a92e2
Add missing `QFile` include to `AboutPage.cpp`
pajlada Feb 19, 2023
d453e3b
Format IRC username-randomizer in IrcServer using QString arg
pajlada Feb 19, 2023
cee7d8c
Comment out usage of `setCodec` in `LinkParser.cpp` for Qt6
pajlada Feb 19, 2023
966fbfa
Comment out usage of `setCodec` in `AboutPage.cpp` for Qt6
pajlada Feb 19, 2023
5ebb90a
Store max spaces as a `qsizetype` in `CommandController`
pajlada Feb 19, 2023
8bd92d5
Use QStringView.split instead of QString splitRef
pajlada Feb 19, 2023
cd81fd2
`int`ify some usages of `size`
pajlada Feb 19, 2023
980d754
Replace QStringRef with QStringView in TwitchMessageBuilder
pajlada Feb 19, 2023
2a1b750
Replace `QStringRef` with `QStringView` in ResizingTextEdit
pajlada Feb 19, 2023
9b577a9
Clarify QPoint constructor in SplitInput.cpp
pajlada Feb 19, 2023
fbee7f8
Use `initFrom` instead of `init` in QStyleOption
pajlada Feb 19, 2023
c35033a
Call `result` on QConcurrent runs in ModerationPage
pajlada Feb 19, 2023
42574b5
Add github workflow for building on Qt6
pajlada Feb 19, 2023
fce67de
Add changelog entry
pajlada Feb 19, 2023
f46de61
Change Qt version to v6.2.4
pajlada Feb 19, 2023
4b96560
Replace `splitRef(':').size()` with `.count()`
pajlada Feb 19, 2023
fea4de6
[Qt 5.12] Add missing `QDebug` include to `BttvLiveUpdateSubscription…
pajlada Feb 19, 2023
47825fe
[Qt 5.12] Continue using `splitRef` and `midRef`
pajlada Feb 19, 2023
c090160
Allow building of Qt6 in CI
pajlada Feb 19, 2023
6e001fb
Include the `qt5compat` module when installing Qt6
pajlada Feb 19, 2023
617f60c
Merge branch 'master' into qt6-build
pajlada Feb 19, 2023
af147b7
Remove QtWidgets/QAction PCH include
pajlada Feb 19, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ jobs:
qt-version: 5.15.2
pch: true
force-lto: false
# Ubuntu 22.04, Qt 6.2.6
- os: ubuntu-22.04
qt-version: 6.2.6
pch: false
force-lto: false
# Test for disabling Precompiled Headers & enabling link-time optimization
- os: ubuntu-22.04
qt-version: 5.15.2
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unversioned

- Dev: Add capability to build Chatterino with Qt6. (#4393)

## 2.4.1

- Major: Added live emote updates for BTTV. (#4147)
Expand Down
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ find_package(Qt${MAJOR_QT_VERSION} REQUIRED
Concurrent
)

if (BUILD_WITH_QT6)
find_package(Qt${MAJOR_QT_VERSION} REQUIRED
COMPONENTS
Core5Compat
)
endif ()

message(STATUS "Qt version: ${Qt${MAJOR_QT_VERSION}_VERSION}")

if (WIN32)
Expand Down
8 changes: 8 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,14 @@ target_link_libraries(${LIBRARY_PROJECT}
LRUCache
MagicEnum
)

if (BUILD_WITH_QT6)
target_link_libraries(${LIBRARY_PROJECT}
PUBLIC
Qt${MAJOR_QT_VERSION}::Core5Compat
)
endif ()

if (BUILD_WITH_QTKEYCHAIN)
target_link_libraries(${LIBRARY_PROJECT}
PUBLIC
Expand Down
5 changes: 5 additions & 0 deletions src/common/LinkParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ namespace {
QFile file(":/tlds.txt");
file.open(QFile::ReadOnly);
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");
#endif
int safetyMax = 20000;

QSet<QString> set;
Expand Down
3 changes: 2 additions & 1 deletion src/controllers/commands/CommandController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
commandName += ' ' + words[i + 1];
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/commands/CommandController.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class CommandController final : public Singleton

// User-created commands
QMap<QString, Command> userCommands_;
int maxSpaces_ = 0;
qsizetype maxSpaces_ = 0;

std::shared_ptr<pajlada::Settings::SettingManager> sm_;
// Because the setting manager is not initialized until the initialize
Expand Down
1 change: 1 addition & 0 deletions src/controllers/sound/SoundController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#define MINIAUDIO_IMPLEMENTATION
#include <miniaudio.h>
#include <QFile>

#include <limits>
#include <memory>
Expand Down
3 changes: 2 additions & 1 deletion src/providers/irc/IrcServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ void IrcServer::initializeConnectionSignals(IrcConnection *connection,

QObject::connect(connection, &Communi::IrcConnection::nickNameRequired,
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,
Expand Down
2 changes: 1 addition & 1 deletion src/providers/twitch/TwitchIrcServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ std::shared_ptr<Channel> TwitchIrcServer::getChannelOrEmptyByID(
continue;

if (twitchChannel->roomId() == channelId &&
twitchChannel->getName().splitRef(":").size() < 3)
QStringView{twitchChannel->getName()}.split(':').size() < 3)
pajlada marked this conversation as resolved.
Show resolved Hide resolved
{
return twitchChannel;
}
Expand Down
10 changes: 5 additions & 5 deletions src/providers/twitch/TwitchMessageBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -821,14 +821,14 @@ void TwitchMessageBuilder::runIgnoreReplaces(
};

auto addReplEmotes = [&twitchEmotes](const IgnorePhrase &phrase,
const QStringRef &midrepl,
const QStringView &midrepl,
int startIndex) mutable {
if (!phrase.containsEmote())
{
return;
}

QVector<QStringRef> words = midrepl.split(' ');
auto words = midrepl.split(' ');
int pos = 0;
for (const auto &word : words)
{
Expand All @@ -843,7 +843,7 @@ void TwitchMessageBuilder::runIgnoreReplaces(
}
twitchEmotes.push_back(TwitchEmoteOccurrence{
startIndex + pos,
startIndex + pos + emote.first.string.length(),
startIndex + pos + (int)emote.first.string.length(),
emote.second,
emote.first,
});
Expand Down Expand Up @@ -905,7 +905,7 @@ void TwitchMessageBuilder::runIgnoreReplaces(
shiftIndicesAfter(from + len, midsize - len);

auto midExtendedRef =
this->originalMessage_.midRef(pos1, pos2 - pos1);
QStringView{this->originalMessage_}.mid(pos1, pos2 - pos1);

for (auto &tup : vret)
{
Expand Down Expand Up @@ -970,7 +970,7 @@ void TwitchMessageBuilder::runIgnoreReplaces(
shiftIndicesAfter(from + len, replacesize - len);

auto midExtendedRef =
this->originalMessage_.midRef(pos1, pos2 - pos1);
QStringView{this->originalMessage_}.mid(pos1, pos2 - pos1);

for (auto &tup : vret)
{
Expand Down
6 changes: 6 additions & 0 deletions src/util/Helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,12 @@ QString localizeNumbers(unsigned int number)
return locale.toString(number);
}

QString localizeNumbers(qsizetype number)
pajlada marked this conversation as resolved.
Show resolved Hide resolved
{
QLocale locale;
pajlada marked this conversation as resolved.
Show resolved Hide resolved
return locale.toString(number);
}

QString kFormatNumbers(const int &number)
{
return QString("%1K").arg(number / 1000);
Expand Down
1 change: 1 addition & 0 deletions src/util/Helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ QString shortenString(const QString &str, unsigned maxWidth = 50);

QString localizeNumbers(const int &number);
QString localizeNumbers(unsigned int number);
QString localizeNumbers(qsizetype number);

QString kFormatNumbers(const int &number);

Expand Down
8 changes: 4 additions & 4 deletions src/widgets/Notebook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -641,8 +641,8 @@ void Notebook::performLayout(bool animated)
bool isLastColumn = col == columnCount - 1;
auto largestWidth = 0;
int tabStart = col * tabsPerColumn;
int tabEnd =
std::min((col + 1) * tabsPerColumn, this->items_.size());
int tabEnd = std::min((col + 1) * tabsPerColumn,
pajlada marked this conversation as resolved.
Show resolved Hide resolved
(int)this->items_.size());

for (int i = tabStart; i < tabEnd; i++)
{
Expand Down Expand Up @@ -743,8 +743,8 @@ void Notebook::performLayout(bool animated)
bool isLastColumn = col == columnCount - 1;
auto largestWidth = 0;
int tabStart = col * tabsPerColumn;
int tabEnd =
std::min((col + 1) * tabsPerColumn, this->items_.size());
int tabEnd = std::min((col + 1) * tabsPerColumn,
pajlada marked this conversation as resolved.
Show resolved Hide resolved
(int)this->items_.size());

for (int i = tabStart; i < tabEnd; i++)
{
Expand Down
1 change: 1 addition & 0 deletions src/widgets/dialogs/SettingsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "widgets/settingspages/NotificationPage.hpp"

#include <QDialogButtonBox>
#include <QFile>
#include <QLineEdit>

namespace chatterino {
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/helper/ResizingTextEdit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ QString ResizingTextEdit::textUnderCursor(bool *hadSpace) const

auto textUpToCursor = currentText.left(tc.selectionStart());

auto words = textUpToCursor.splitRef(' ');
auto words = QStringView{textUpToCursor}.split(' ');
if (words.size() == 0)
{
return QString();
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/helper/SettingsDialogTab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void SettingsDialogTab::paintEvent(QPaintEvent *)
QPainter painter(this);

QStyleOption opt;
opt.init(this);
opt.initFrom(this);

this->style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter, this);

Expand Down
5 changes: 5 additions & 0 deletions src/widgets/settingspages/AboutPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "widgets/BasePopup.hpp"
#include "widgets/helper/SignalLabel.hpp"

#include <QFile>
#include <QFormLayout>
#include <QGroupBox>
#include <QLabel>
Expand Down Expand Up @@ -144,7 +145,11 @@ AboutPage::AboutPage()
contributorsFile.open(QFile::ReadOnly);

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");
#endif

QString line;

Expand Down
43 changes: 22 additions & 21 deletions src/widgets/settingspages/ModerationPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,35 +112,36 @@ ModerationPage::ModerationPage()
// Show how big (size-wise) the logs are
auto logsPathSizeLabel = logs.emplace<QLabel>();
logsPathSizeLabel->setText(QtConcurrent::run([] {
return fetchLogDirectorySize();
}));
return fetchLogDirectorySize();
}).result());

// Select event
QObject::connect(selectDir.getElement(), &QPushButton::clicked, this,
[this, logsPathSizeLabel]() mutable {
auto dirName =
QFileDialog::getExistingDirectory(this);
QObject::connect(
selectDir.getElement(), &QPushButton::clicked, this,
[this, logsPathSizeLabel]() mutable {
auto dirName = QFileDialog::getExistingDirectory(this);

getSettings()->logPath = dirName;
getSettings()->logPath = dirName;

// Refresh: Show how big (size-wise) the logs are
logsPathSizeLabel->setText(QtConcurrent::run([] {
return fetchLogDirectorySize();
}));
});
// Refresh: Show how big (size-wise) the logs are
logsPathSizeLabel->setText(QtConcurrent::run([] {
return fetchLogDirectorySize();
}).result());
});

buttons->addSpacing(16);

// Reset custom logpath
QObject::connect(resetDir.getElement(), &QPushButton::clicked, this,
[logsPathSizeLabel]() mutable {
getSettings()->logPath = "";

// Refresh: Show how big (size-wise) the logs are
logsPathSizeLabel->setText(QtConcurrent::run([] {
return fetchLogDirectorySize();
}));
});
QObject::connect(
resetDir.getElement(), &QPushButton::clicked, this,
[logsPathSizeLabel]() mutable {
getSettings()->logPath = "";

// Refresh: Show how big (size-wise) the logs are
logsPathSizeLabel->setText(QtConcurrent::run([] {
return fetchLogDirectorySize();
}).result());
});

QCheckBox *onlyLogListedChannels =
this->createCheckBox("Only log channels listed below",
Expand Down
6 changes: 3 additions & 3 deletions src/widgets/splits/SplitInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ void SplitInput::updateCompletionPopup()
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] == ' ')
{
Expand Down Expand Up @@ -766,7 +766,7 @@ void SplitInput::showCompletionPopup(const QString &text, bool emoteCompletion)
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);

popup->move(pos);
Expand All @@ -789,7 +789,7 @@ void SplitInput::insertCompletionText(const QString &input_) const
auto text = edit.toPlainText();
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;
if (text[i] == ':')
Expand Down