From 4d41d5e7ec7ae285523c9a47bd898d81105db9c3 Mon Sep 17 00:00:00 2001
From: Sergey Fedorov <vital.had@gmail.com>
Date: Fri, 17 Oct 2025 08:02:39 +0800
Subject: [PATCH] Unbreak build with Qt4

---
 src/FileHistory.cc      |  2 +-
 src/commitimpl.cpp      |  5 +++
 src/fileview.cpp        |  4 +++
 src/git.cpp             | 78 +++++++++++++++++++++++++++++++++++++----
 src/git.h               | 13 +++++++
 src/inputdialog.cpp     | 17 ++++++++-
 src/listview.cpp        |  2 +-
 src/listview.h          |  4 +++
 src/mainimpl.cpp        | 12 +++++--
 src/mainimpl.h          |  5 +++
 src/patchcontent.cpp    | 38 +++++++++++++++++---
 src/patchcontent.h      | 12 +++++++
 src/rangeselectimpl.cpp | 11 +++++-
 src/revdesc.cpp         | 13 +++++--
 src/settingsimpl.cpp    |  4 +++
 15 files changed, 201 insertions(+), 19 deletions(-)

diff --git src/FileHistory.cc src/FileHistory.cc
index d479116..2c5b6d4 100644
--- src/FileHistory.cc
+++ src/FileHistory.cc
@@ -122,7 +122,7 @@ void FileHistory::clear(bool complete) {
   rowData.clear();
 
   if (testFlag(REL_DATE_F)) {
-#if QT_VERSION >= 0x06000
+#if QT_VERSION >= 0x060000
     secs = QDateTime::currentDateTime().toSecsSinceEpoch();
 #else
     secs = QDateTime::currentDateTime().toTime_t();
diff --git src/commitimpl.cpp src/commitimpl.cpp
index d69024f..5370d8b 100644
--- src/commitimpl.cpp
+++ src/commitimpl.cpp
@@ -8,7 +8,12 @@
 #include <QTextCodec>
 #include <QSettings>
 #include <QMenu>
+#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
+#include <QRegExp>
+#define QRegularExpression QRegExp
+#else
 #include <QRegularExpression>
+#endif
 #include <QDir>
 #include <QMessageBox>
 #include <QInputDialog>
diff --git src/fileview.cpp src/fileview.cpp
index 5a851ce..4e48e39 100644
--- src/fileview.cpp
+++ src/fileview.cpp
@@ -17,6 +17,10 @@
 
 #define MAX_LINE_NUM 5
 
+#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
+#define QRegularExpression QRegExp
+#endif
+
 FileView::FileView(MainImpl* mi, Git* g) : Domain(mi, g, false) {
 
 	fileTab = new Ui_TabFile();
diff --git src/git.cpp src/git.cpp
index f125bb8..bba9d00 100644
--- src/git.cpp
+++ src/git.cpp
@@ -12,7 +12,11 @@
 #include <QFile>
 #include <QImageReader>
 #include <QPalette>
+#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
+#include <QRegExp>
+#else
 #include <QRegularExpression>
+#endif
 //#include <QSet> //CT TODO remove
 #include <QSettings>
 #include <QTextCodec>
@@ -425,9 +429,11 @@ const QString Git::getTagMsg(SCRef sha) {
 
 	if (!rf.tagMsg.isEmpty())
 		return rf.tagMsg;
-
+#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
+	QRegExp pgp("-----BEGIN PGP SIGNATURE*END PGP SIGNATURE-----", Qt::CaseSensitive, QRegExp::Wildcard);
+#else
 	QRegularExpression pgp("-----BEGIN PGP SIGNATURE.*END PGP SIGNATURE-----", QRegularExpression::DotMatchesEverythingOption);
-
+#endif
 	if (!rf.tagObj.isEmpty()) {
 		QString ro;
 		if (run("git cat-file tag " + rf.tagObj, &ro))
@@ -1006,8 +1012,11 @@ const QString Git::getNewCommitMsg() {
 		return "";
 	}
 	QString status = c->longLog();
+#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
+	status.prepend('\n').replace(QRegExp("\\n([^#\\n]?)"), "\n#\\1"); // comment all the lines
+#else
 	status.prepend('\n').replace(QRegularExpression("\\n([^#\\n]?)"), "\n#\\1"); // comment all the lines
-
+#endif
 	if (isMergeHead) {
 		QFile file(QDir(gitDir).absoluteFilePath("MERGE_MSG"));
 		if (file.open(QIODevice::ReadOnly)) {
@@ -1023,6 +1032,27 @@ const QString Git::getNewCommitMsg() {
 }
 
 //CT TODO utility function; can go elsewhere
+#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
+const QString Git::colorMatch(SCRef txt, QRegExp& regExp) {
+
+	QString text = qt4and5escaping(txt);
+
+	if (regExp.isEmpty())
+		return text;
+
+	SCRef startCol(QString::fromLatin1("<b><font color=\"red\">"));
+	SCRef endCol(QString::fromLatin1("</font></b>"));
+	int pos = 0;
+	while ((pos = text.indexOf(regExp, pos)) != -1) {
+
+		SCRef match(regExp.cap(0));
+		const QString coloredText(startCol + match + endCol);
+		text.replace(pos, match.length(), coloredText);
+		pos += coloredText.length();
+	}
+	return text;
+}
+#else
 const QString Git::colorMatch(SCRef txt, QRegularExpression& regExp) {
 
 	QString text = qt4and5escaping(txt);
@@ -1043,6 +1073,7 @@ const QString Git::colorMatch(SCRef txt, QRegularExpression& regExp) {
 	}
 	return text;
 }
+#endif
 
 //CT TODO utility function; can go elsewhere
 const QString Git::formatList(SCList sl, SCRef name, bool inOneLine) {
@@ -1057,9 +1088,14 @@ const QString Git::formatList(SCList sl, SCRef name, bool inOneLine) {
 	return ls;
 }
 
+#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
+const QString Git::getDesc(SCRef sha, QRegExp& shortLogRE, QRegExp& longLogRE,
+                           bool showHeader, FileHistory* fh)
+#else
 const QString Git::getDesc(SCRef sha, QRegularExpression& shortLogRE, QRegularExpression& longLogRE,
-                           bool showHeader, FileHistory* fh) {
-
+                           bool showHeader, FileHistory* fh)
+#endif
+	{
 	if (sha.isEmpty())
 		return "";
 
@@ -1122,6 +1158,28 @@ const QString Git::getDesc(SCRef sha, QRegularExpression& shortLogRE, QRegularEx
 	// sha if there isn't a leading trailing space or an open parenthesis and,
 	// in that case, before the space must not be a ':' character.
 	// It's an ugly heuristic, but seems to work in most cases.
+#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
+	QRegExp reSHA("..[0-9a-f]{21,40}|[^:][\\s(][0-9a-f]{6,20}", Qt::CaseInsensitive);
+	reSHA.setMinimal(false);
+	int pos = 0;
+	while ((pos = text.indexOf(reSHA, pos)) != -1) {
+
+		SCRef ref = reSHA.cap(0).mid(2);
+		const Rev* r = (ref.length() == 40 ? revLookup(ref) : revLookup(getRefSha(ref)));
+		if (r && r->sha() != ZERO_SHA_RAW) {
+			QString slog(r->shortLog());
+			if (slog.isEmpty()) // very rare but possible
+				slog = r->sha();
+			if (slog.length() > 60)
+				slog = slog.left(57).trimmed().append("...");
+
+			const QString link("<a href=\"" + r->sha() + "\">" + qt4and5escaping(slog) + "</a>");
+			text.replace(pos + 2, ref.length(), link);
+			pos += link.length();
+		} else
+			pos += reSHA.cap(0).length();
+	}
+#else
 	QRegularExpression reSHA("..[0-9a-f]{21,40}|[^:][\\s(][0-9a-f]{6,20}", QRegularExpression::CaseInsensitiveOption);
 	int pos = 0;
 	QRegularExpressionMatch match;
@@ -1142,6 +1200,7 @@ const QString Git::getDesc(SCRef sha, QRegularExpression& shortLogRE, QRegularEx
 		} else
 			pos += match.captured(0).length();
 	}
+#endif
 	return text;
 }
 
@@ -1673,7 +1732,11 @@ const QString Git::getLocalDate(SCRef gitDate) {
         // cache miss
         if (localDate.isEmpty()) {
                 static QDateTime d;
+#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
+                d.setTime_t(gitDate.toUInt());
+#else
                 d.setSecsSinceEpoch(gitDate.toUInt());
+#endif
                 localDate = QLocale::system().toString(d, QLocale::ShortFormat);
 
                 // save to cache
@@ -1980,8 +2043,11 @@ const Rev* Git::fakeWorkDirRev(SCRef parent, SCRef log, SCRef longLog, int idx,
         QString patch;
         if (!isMainHistory(fh))
                 patch = getWorkDirDiff(fh->fileNames().first());
-
+#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
+        QString date(QString::number(QDateTime::currentDateTime().toTime_t()));
+#else
         QString date(QString::number(QDateTime::currentDateTime().toSecsSinceEpoch()));
+#endif
         QString author("-");
         QStringList parents(parent);
         Rev* c = fakeRevData(ZERO_SHA, parents, author, date, log, longLog, patch, idx, fh);
diff --git src/git.h src/git.h
index 2cbb876..4411eaf 100644
--- src/git.h
+++ src/git.h
@@ -10,7 +10,12 @@
 #include "exceptionmanager.h"
 #include "common.h"
 
+#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
+template <class, class> struct QPair;
+class QRegExp;
+#else
 class QRegularExpression;
+#endif
 class QTextCodec;
 class Annotate;
 //class DataLoader;
@@ -97,7 +102,11 @@ public:
 	bool getTree(SCRef ts, TreeInfo& ti, bool wd, SCRef treePath);
 	static const QString getLocalDate(SCRef gitDate);
 	const QString getCurrentBranchName() const {return curBranchName;}
+#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
+	const QString getDesc(SCRef sha, QRegExp& slogRE, QRegExp& lLogRE, bool showH, FileHistory* fh);
+#else
 	const QString getDesc(SCRef sha, QRegularExpression& slogRE, QRegularExpression& lLogRE, bool showH, FileHistory* fh);
+#endif
 	const QString getLastCommitMsg();
 	const QString getNewCommitMsg();
 	const QString getLaneParent(SCRef fromSHA, int laneNum);
@@ -246,7 +255,11 @@ private:
 	const QStringList getOthersFiles();
 	const QStringList getOtherFiles(SCList selFiles, bool onlyInIndex);
 	const QString getNewestFileName(SCList args, SCRef fileName);
+#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
+	static const QString colorMatch(SCRef txt, QRegExp& regExp);
+#else
 	static const QString colorMatch(SCRef txt, QRegularExpression& regExp);
+#endif
 	void appendFileName(RevFile& rf, SCRef name, FileNamesLoader& fl);
 	void flushFileNames(FileNamesLoader& fl);
 	void populateFileNamesMap();
diff --git src/inputdialog.cpp src/inputdialog.cpp
index 9b6e449..5a9a917 100644
--- src/inputdialog.cpp
+++ src/inputdialog.cpp
@@ -11,6 +11,10 @@
 #include <QListView>
 #include <QStringListModel>
 
+#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
+#define QRegularExpression QRegExp
+#endif
+
 namespace QGit {
 
 InputDialog::WidgetItem::WidgetItem() : widget(NULL)
@@ -92,12 +96,20 @@ InputDialog::InputDialog(const QString &cmd, const VariableMap &variables,
 	QRegularExpression re("%(([a-z_]+)([[]([a-z ,]+)[]])?:)?([^%=]+)(=[^%]+)?%");
 	int start = 0;
 	int row = 0;
+#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
+	while ((start = re.indexIn(cmd, start)) != -1) {
+		const QString type = re.cap(2);
+		const QStringList opts = re.cap(4).split(',', QGIT_SPLITBEHAVIOR(SkipEmptyParts));
+		const QString name = re.cap(5);
+		const QString value = re.cap(6).mid(1);
+#else
 	QRegularExpressionMatch match;
 	while ((start = cmd.indexOf(re, start, &match)) != -1) {
 		const QString type = match.captured(2);
 		const QStringList opts = match.captured(4).split(',', QGIT_SPLITBEHAVIOR(SkipEmptyParts));
 		const QString name = match.captured(5);
 		const QString value = match.captured(6).mid(1);
+#endif
 		if (widgets.count(name)) { // widget already created
 			if (!type.isEmpty()) dbs("token must not be redefined: " + name);
 			continue;
@@ -105,8 +117,11 @@ InputDialog::InputDialog(const QString &cmd, const VariableMap &variables,
 
 		WidgetItemPtr item (new WidgetItem());
 		item->start = start;
+#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
+		item->end = start = start + re.matchedLength();
+#else
 		item->end = start = start + match.capturedLength();
-
+#endif
 		if (type == "combobox") {
 			QComboBox *w = new QComboBox(this);
 			w->addItems(parseStringList(value, variables));
diff --git src/listview.cpp src/listview.cpp
index e3f6396..7b25a94 100644
--- src/listview.cpp
+++ src/listview.cpp
@@ -1230,7 +1230,7 @@ void ListViewDelegate::addTextPixmap(QPixmap** pp, SCRef txt, const QStyleOption
 #if QT_VERSION >= QT_VERSION_CHECK(5,11,0)
 			unsigned int fmw = fm.horizontalAdvance(txt);
 #else
-			unsigned int fmw = fm.width(txt)
+			unsigned int fmw = fm.width(txt);
 #endif
 	unsigned int text_width = fmw + 2 * text_spacing;
 	unsigned int text_height = fm.height();
diff --git src/listview.h src/listview.h
index 2b8dd3f..1a6dd41 100644
--- src/listview.h
+++ src/listview.h
@@ -9,7 +9,11 @@
 #include <QTreeView>
 #include <QItemDelegate>
 #include <QSortFilterProxyModel>
+#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
+#include <QRegExp>
+#else
 #include <QRegularExpression>
+#endif
 #include "common.h"
 
 class Git;
diff --git src/mainimpl.cpp src/mainimpl.cpp
index f8cc246..343b77e 100644
--- src/mainimpl.cpp
+++ src/mainimpl.cpp
@@ -74,9 +74,15 @@ MainImpl::MainImpl(SCRef cd, QWidget* p) : QMainWindow(p) {
 	setRepositoryBusy = false;
 
 	// init filter match highlighters
+#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
+	shortLogRE.setMinimal(true);
+	shortLogRE.setCaseSensitivity(Qt::CaseInsensitive);
+	longLogRE.setMinimal(true);
+	longLogRE.setCaseSensitivity(Qt::CaseInsensitive);
+#else
 	shortLogRE.setPatternOptions(QRegularExpression::CaseInsensitiveOption);
 	longLogRE.setPatternOptions(QRegularExpression::CaseInsensitiveOption);
-
+#endif
 	// set-up standard revisions and files list font
 	QSettings settings;
 	QString font(settings.value(STD_FNT_KEY).toString());
@@ -1649,7 +1655,7 @@ bool MainImpl::askApplyPatchParameters(bool* workDirOnly, bool* fold) {
 			"Apply Patch",
 			"Do you want to commit or just to apply changes to "
 			"working directory?",
-			{}, this);
+			QMessageBox::NoButton, this);
 		QAbstractButton* cbtn = qmb.addButton("&Cancel", QMessageBox::ButtonRole::RejectRole);
 		QAbstractButton* wdbtn = qmb.addButton(
 					"&Working directory", QMessageBox::ButtonRole::AcceptRole);
@@ -1662,7 +1668,7 @@ bool MainImpl::askApplyPatchParameters(bool* workDirOnly, bool* fold) {
 		QMessageBox qmb(QMessageBox::Question,
 			"Apply Patch",
 			"Do you want to import or fold the patch?",
-			{}, this);
+			QMessageBox::NoButton, this);
 		QAbstractButton* cbtn = qmb.addButton("&Cancel", QMessageBox::ButtonRole::RejectRole);
 		QAbstractButton* fbtn = qmb.addButton(
 					"&Fold", QMessageBox::ButtonRole::AcceptRole);
diff --git src/mainimpl.h src/mainimpl.h
index 2d0afb7..c6f1e42 100644
--- src/mainimpl.h
+++ src/mainimpl.h
@@ -8,7 +8,12 @@
 #define MAINIMPL_H
 
 #include <QProcess>
+#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
+#include <QRegExp>
+#define QRegularExpression QRegExp
+#else
 #include <QRegularExpression>
+#endif
 #include <QDir>
 #include "exceptionmanager.h"
 #include "common.h"
diff --git src/patchcontent.cpp src/patchcontent.cpp
index 3fab645..fd44850 100644
--- src/patchcontent.cpp
+++ src/patchcontent.cpp
@@ -95,9 +95,12 @@ PatchContent::PatchContent(QWidget* parent) : QTextEdit(parent) {
 
 	diffLoaded = seekTarget = false;
 	curFilter = prevFilter = VIEW_ALL;
-
+#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
+	pickAxeRE.setMinimal(true);
+	pickAxeRE.setCaseSensitivity(Qt::CaseInsensitive);
+#else
 	pickAxeRE.setPatternOptions(QRegularExpression::CaseInsensitiveOption);
-
+#endif
 	setFont(QGit::TYPE_WRITER_FONT);
 	diffHighlighter = new DiffHighlighter(this);
 }
@@ -315,19 +318,37 @@ void PatchContent::procFinished() {
 	}
 }
 
+#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
+int PatchContent::doSearch(SCRef txt, int pos) {
+
+	if (isRegExp)
+		return txt.indexOf(pickAxeRE, pos);
+
+	return txt.indexOf(pickAxeRE.pattern(), pos, Qt::CaseInsensitive);
+}
+#endif
+
 bool PatchContent::computeMatches() {
 
 	matches.clear();
+#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
+	if (pickAxeRE.isEmpty())
+#else
 	if (pickAxeRE.pattern().isEmpty())
+#endif
 		return false;
 
 	SCRef txt = toPlainText();
 	int pos, lastPos = 0, lastPara = 0;
 
 	// must be at the end to catch patterns across more the one chunk
+#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
+	while ((pos = doSearch(txt, lastPos)) != -1)
+#else
 	QRegularExpressionMatch match;
-	while ((pos = txt.indexOf(pickAxeRE, pos, &match)) != -1) {
-
+	while ((pos = txt.indexOf(pickAxeRE, pos, &match)) != -1)
+#endif
+	{
 		matches.append(MatchSelection());
 		MatchSelection& s = matches.last();
 
@@ -336,7 +357,11 @@ bool PatchContent::computeMatches() {
 		s.indexFrom = pos - txt.lastIndexOf('\n', pos) - 1; // index starts from 0
 
 		lastPos = pos;
+#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
+		pos += (isRegExp ? pickAxeRE.matchedLength() : pickAxeRE.pattern().length());
+#else
 		pos += match.capturedLength();
+#endif
 		pos--;
 
 		s.paraTo = s.paraFrom + txt.mid(lastPos, pos - lastPos).count('\n');
@@ -362,7 +387,12 @@ bool PatchContent::getMatch(int para, int* indexFrom, int* indexTo) {
 }
 
 void PatchContent::on_highlightPatch(const QString& exp, bool re) {
+#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
+	pickAxeRE.setPattern(exp);
+	isRegExp = re;
+#else
 	pickAxeRE.setPattern(re ? exp : QRegularExpression::escape(exp));
+#endif
 	if (diffLoaded)
 		procFinished();
 }
diff --git src/patchcontent.h src/patchcontent.h
index df9ff7d..5c38073 100644
--- src/patchcontent.h
+++ src/patchcontent.h
@@ -8,7 +8,11 @@
 #define PATCHCONTENT_H
 
 #include <QPointer>
+#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
+#include <QRegExp>
+#else
 #include <QRegularExpression>
+#endif
 #include <QTextEdit>
 #include <QSyntaxHighlighter>
 #include "common.h"
@@ -58,6 +62,9 @@ private:
 	int positionToLineNum(int pos);
 	int topToLineNum();
 	void saveRestoreSizes(bool startup = false);
+#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
+	int doSearch(const QString& txt, int pos);
+#endif
 	bool computeMatches();
 	bool getMatch(int para, int* indexFrom, int* indexTo);
 	void centerMatch(int id = 0);
@@ -70,7 +77,12 @@ private:
 	bool diffLoaded;
 	QByteArray patchRowData;
 	QString halfLine;
+#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
+	bool isRegExp;
+	QRegExp pickAxeRE;
+#else
 	QRegularExpression pickAxeRE;
+#endif
 	QString target;
 	bool seekTarget;
 
diff --git src/rangeselectimpl.cpp src/rangeselectimpl.cpp
index a60fccd..2900b50 100644
--- src/rangeselectimpl.cpp
+++ src/rangeselectimpl.cpp
@@ -7,7 +7,12 @@
 
 */
 #include <QSettings>
+#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
+#include <QRegExp>
+#define QRegularExpression QRegExp
+#else
 #include <QRegularExpression>
+#endif
 #include "common.h"
 #include "git.h"
 #include "rangeselectimpl.h"
@@ -101,10 +106,14 @@ void RangeSelectImpl::orderRefs(const QStringList& src, QStringList& dst) {
 	FOREACH_SL (it, src) {
 
 		QString tmpStr(*it);
-
+#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
+		if (re.indexIn(tmpStr) != -1)
+			tmpStr.insert(re.pos(1), rcMark);
+#else
 		QRegularExpressionMatch match;
 		if (tmpStr.indexOf(re, 0, &match) != -1)
 			tmpStr.insert(match.capturedStart(1), rcMark);
+#endif
 		else
 			tmpStr += noRcMark;
 
diff --git src/revdesc.cpp src/revdesc.cpp
index 185d2dd..c6cd708 100644
--- src/revdesc.cpp
+++ src/revdesc.cpp
@@ -6,7 +6,11 @@
 #include <QApplication>
 #include <QMenu>
 #include <QContextMenuEvent>
+#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
+#include <QRegExp>
+#else
 #include <QRegularExpression>
+#endif
 #include <QClipboard>
 #include "domain.h"
 #include "revdesc.h"
@@ -22,9 +26,14 @@ RevDesc::RevDesc(QWidget* p) : QTextBrowser(p), d(NULL) {
 
 void RevDesc::on_anchorClicked(const QUrl& link) {
 
+#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
+	QRegExp re("[0-9a-f]{40}", Qt::CaseInsensitive);
+	if (re.exactMatch(link.toString()))
+#else
 	QRegularExpression re("[0-9a-f]{40}", QRegularExpression::CaseInsensitiveOption);
-	if (re.match(link.toString()).hasMatch()) {
-
+	if (re.match(link.toString()).hasMatch())
+#endif
+	{
 		setSource(QUrl()); // override default navigation behavior
 		d->st.setSha(link.toString());
 		UPDATE_DOMAIN(d);
diff --git src/settingsimpl.cpp src/settingsimpl.cpp
index 6ed65d6..4cd3021 100644
--- src/settingsimpl.cpp
+++ src/settingsimpl.cpp
@@ -212,7 +212,11 @@ void SettingsImpl::setupCodecsCombo() {
 		return;
 	}
 	const QString curCodec(tc != 0 ? tc->name() : "Latin1");
+#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
+	QRegExp re("*" + curCodec + "*", Qt::CaseInsensitive, QRegExp::Wildcard);
+#else
 	QRegularExpression re("^.*" + QRegularExpression::escape(curCodec) + ".*$", QRegularExpression::CaseInsensitiveOption);
+#endif
 	int idx = codecs.indexOf(re);
 	if (idx == -1) {
 		dbp("ASSERT: codec <%1> not available, using local codec", curCodec);
-- 
2.51.0

