Skip to content

Commit

Permalink
fix: Failed to compile in Qt5 environment
Browse files Browse the repository at this point in the history
Refactored the resource handling in CMakeLists.txt to support both
Qt5 and Qt6 versions

Additionally, updated string splitting logic across multiple files
to ensure compatibility with different Qt versions.
  • Loading branch information
Kakueeen committed Nov 19, 2024
1 parent 5c8ec59 commit 1db6687
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 3 deletions.
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,11 @@ IF("${srcdir}" STREQUAL "gtk")
ENDFOREACH()

ELSEIF("${srcdir}" STREQUAL "qt")
QT_ADD_RESOURCES(gimagereader_RESOURCES_RCC ${gimagereader_RESOURCES})
IF("${INTERFACE_TYPE}" STREQUAL "qt5")
QT5_ADD_RESOURCES(gimagereader_RESOURCES_RCC ${gimagereader_RESOURCES})
ELSE()
QT_ADD_RESOURCES(gimagereader_RESOURCES_RCC ${gimagereader_RESOURCES})
ENDIF()
SET(UIC_EXECUTABLE Qt${QT_VER}::uic)

# Custom WRAP_UI which also gettext-izes the result
Expand Down
7 changes: 6 additions & 1 deletion qt/src/ConfigSettings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ TableSetting::TableSetting(const QString& key, QTableWidget* table)
m_table->setRowCount(0);
int nCols = m_table->columnCount();

for(const QString& row : str.split(';', Qt::SkipEmptyParts)) {
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QStringList rowList = str.split(';', QString::SkipEmptyParts);
#else
QStringList rowList = str.split(';', Qt::SkipEmptyParts);
#endif
for(const QString& row : rowList) {
int colidx = 0;
QStringList cols = row.split(',');
if(cols.size() != nCols) {
Expand Down
4 changes: 4 additions & 0 deletions qt/src/CrashHandler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ void CrashHandler::handleGdbFinished(int exitCode, QProcess::ExitStatus exitStat
if(exitCode != 0 || exitStatus != QProcess::NormalExit) {
ui.plainTextEditBacktrace->appendPlainText(_("Failed to obtain backtrace. Is GDB installed?"));
} else {
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QStringList lines = ui.plainTextEditBacktrace->toPlainText().split("\n", QString::SkipEmptyParts);
#else
QStringList lines = ui.plainTextEditBacktrace->toPlainText().split("\n", Qt::SkipEmptyParts);
#endif
ui.plainTextEditBacktrace->setPlainText(lines[0]);
ui.plainTextEditBacktrace->appendPlainText("\n");
for(int i = 1, n = lines.length(); i < n; ++i) {
Expand Down
1 change: 1 addition & 0 deletions qt/src/DisplayRenderer.hh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <QByteArray>
#include <QString>
#include <QMutex>
#include <memory>

class DjVuDocument;

Expand Down
17 changes: 17 additions & 0 deletions qt/src/FileTreeModel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ QModelIndex FileTreeModel::insertFile(QString filePath, DataObject* data, const
return index(row, 0, index(0, 0));
} else if(m_root->path.startsWith(fileDir)) {
// Root below new path, replace root
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QStringList path = m_root->path.mid(fileDir.length()).split("/", QString::SkipEmptyParts);
#else
QStringList path = m_root->path.mid(fileDir.length()).split("/", Qt::SkipEmptyParts);
#endif
beginRemoveRows(QModelIndex(), 0, 0);
DirNode* oldroot = m_root;
m_root = nullptr;
Expand All @@ -91,7 +95,11 @@ QModelIndex FileTreeModel::insertFile(QString filePath, DataObject* data, const
return index(1, 0, index(0, 0));
} else if(fileDir.startsWith(m_root->path)) {
// New path below root, append to subtree
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QStringList path = fileDir.mid(m_root->path.length()).split("/", QString::SkipEmptyParts);
#else
QStringList path = fileDir.mid(m_root->path.length()).split("/", Qt::SkipEmptyParts);
#endif
DirNode* cur = m_root;
QModelIndex idx = index(0, 0);
for(const QString& part : path) {
Expand All @@ -116,8 +124,13 @@ QModelIndex FileTreeModel::insertFile(QString filePath, DataObject* data, const
return index(row, 0, idx);
} else {
// Unrelated trees, find common ancestor
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QStringList rootPath = m_root->path.split("/", QString::SkipEmptyParts);
QStringList newPath = fileDir.split("/", QString::SkipEmptyParts);
#else
QStringList rootPath = m_root->path.split("/", Qt::SkipEmptyParts);
QStringList newPath = fileDir.split("/", Qt::SkipEmptyParts);
#endif
int pos = 0;
for(int n = qMin(rootPath.length(), newPath.length()); pos < n; ++pos) {
if(rootPath[pos] != newPath[pos]) {
Expand Down Expand Up @@ -194,7 +207,11 @@ QModelIndex FileTreeModel::findFile(const QString& filePath, bool isFile) const
return QModelIndex();
}
QString relPath = fileDir.mid(cur->path.length());
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QStringList parts = relPath.split("/", QString::SkipEmptyParts);
#else
QStringList parts = relPath.split("/", Qt::SkipEmptyParts);
#endif
for(const QString& part : parts) {
auto it = cur->dirs.find(part);
if(it == cur->dirs.end()) {
Expand Down
4 changes: 4 additions & 0 deletions qt/src/RecognitionMenu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,11 @@ void RecognitionMenu::rebuild() {
m_multilingualAction->setCheckable(true);
m_menuMultilanguage = new QMenu();
isMultilingual = curlang.prefix.contains('+');
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QStringList sellangs = curlang.prefix.split('+', QString::SkipEmptyParts);
#else
QStringList sellangs = curlang.prefix.split('+', Qt::SkipEmptyParts);
#endif
for(const QString& langprefix : availLanguages) {
if(langprefix == "osd") {
continue;
Expand Down
11 changes: 10 additions & 1 deletion qt/src/Recognizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,17 @@ QList<int> Recognizer::selectPages(bool& autodetectLayout) {
QString text = m_pagesDialogUi.lineEditPageRange->text();
if((match = validateRegEx.match(text)).hasMatch()) {
text.replace(QRegularExpression("\\s+"), "");
for(const QString& block : text.split(',', Qt::SkipEmptyParts)) {
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QStringList blockList = text.split(',', QString::SkipEmptyParts);
#else
QStringList blockList = text.split(',', Qt::SkipEmptyParts);
#endif
for(const QString& block : blockList) {
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QStringList ranges = block.split('-', QString::SkipEmptyParts);
#else
QStringList ranges = block.split('-', Qt::SkipEmptyParts);
#endif
if(ranges.size() == 1) {
int page = ranges[0].toInt();
if(page > 0 && page <= nPages) {
Expand Down

0 comments on commit 1db6687

Please sign in to comment.