From 1fc59b83c2fbc5cb74e76c97090ef99aa782c652 Mon Sep 17 00:00:00 2001
From: Sergey Fedorov <barracuda@macos-powerpc.org>
Date: Mon, 30 Jun 2025 17:19:17 +0800
Subject: [PATCH] Fix the build with Qt4

Among other fixes:

This reverts commit 4e265a52ecdd96ab79e2efe6d727bc129506ffa5.
This reverts commit a5a4c40803a9a5b914f89bef39685baf77865f87.
This reverts commit 29b61805f7d41011e6e5feb72854d30fd9b88b38.
This reverts commit 86cb8acc303f047040fb8fc09f5149ff176d4d93.
This reverts commit 60836291f6949e731158c7c4695f672cb4d87f7f.
This reverts commit 62be87604c17f22d2aa1732012048bab93ab13db.
---
 CMakeLists.txt                     | 18 +++-----
 cmake/qtermwidget4-config.cmake.in | 20 +++++++++
 lib/ColorScheme.cpp                | 36 ++++++++-------
 lib/ColorScheme.h                  |  4 +-
 lib/Emulation.cpp                  | 30 +++++++------
 lib/Emulation.h                    |  5 ++-
 lib/Filter.cpp                     | 14 +++---
 lib/Filter.h                       | 11 +++--
 lib/KeyboardTranslator.cpp         | 10 ++---
 lib/Pty.cpp                        |  2 +-
 lib/SearchBar.cpp                  | 12 ++---
 lib/SearchBar.h                    |  4 +-
 lib/Session.cpp                    | 20 ++++-----
 lib/ShellCommand.cpp               |  4 +-
 lib/TerminalDisplay.cpp            | 72 ++++++++++++++----------------
 lib/Vt102Emulation.cpp             |  4 +-
 lib/kprocess.cpp                   | 14 +++++-
 lib/kprocess.h                     | 23 +++++++---
 lib/kpty.cpp                       |  3 +-
 lib/kpty.h                         |  5 +--
 lib/kptyprocess.cpp                | 21 +++++----
 lib/kptyprocess.h                  | 10 +++--
 lib/qtermwidget.cpp                | 27 +++++------
 lib/qtermwidget.h                  |  1 -
 lib/tools.cpp                      |  4 +-
 lib/tools.h                        |  3 --
 pyqt/sip/qtermwidget.sip           |  2 +-
 27 files changed, 209 insertions(+), 170 deletions(-)
 create mode 100644 cmake/qtermwidget4-config.cmake.in

diff --git a/CMakeLists.txt b/CMakeLists.txt
index ce50ed0..cc4329f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -18,7 +18,6 @@ option(QTERMWIDGET_USE_UTEMPTER "Uses libutempter on Linux or libulog on FreeBSD
 option(QTERMWIDGET_BUILD_PYTHON_BINDING "Build python binding" OFF)
 option(USE_UTF8PROC "Use libutf8proc for better Unicode support. Default OFF" OFF)
 
-
 # just change version for releases
 # keep this in sync with the version in pyqt/pyproject.toml
 set(QTERMWIDGET_VERSION_MAJOR "1")
@@ -32,11 +31,9 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake")
 set(CMAKE_INCLUDE_CURRENT_DIR ON)
 
 # Minimum Versions
-set(QT_MINIMUM_VERSION "5.15.0")
 set(LXQTBT_MINIMUM_VERSION "0.13.0")
 
-find_package(Qt5Widgets "${QT_MINIMUM_VERSION}" REQUIRED)
-find_package(Qt5LinguistTools "${QT_MINIMUM_VERSION}" REQUIRED)
+find_package(Qt4 COMPONENTS QtCore QtGui QtXml REQUIRED)
 find_package(lxqt-build-tools ${LXQTBT_MINIMUM_VERSION} REQUIRED)
 
 if(USE_UTF8PROC)
@@ -55,8 +52,7 @@ if(APPLE)
     endif()
 endif()
 
-set(QTERMWIDGET_LIBRARY_NAME qtermwidget5)
-
+set(QTERMWIDGET_LIBRARY_NAME qtermwidget4)
 
 # main library
 
@@ -130,9 +126,9 @@ set(QTERMWIDGET_INCLUDE_DIR "${CMAKE_INSTALL_FULL_INCLUDEDIR}/${QTERMWIDGET_LIBR
 
 CHECK_FUNCTION_EXISTS(updwtmpx HAVE_UPDWTMPX)
 
-qt5_wrap_cpp(MOCS ${HDRS})
-qt5_wrap_ui(UI_SRCS ${UI})
-set(PKG_CONFIG_REQ "Qt5Widgets")
+qt4_wrap_cpp(MOCS ${HDRS})
+qt4_wrap_ui(UI_SRCS ${UI})
+set(PKG_CONFIG_REQ "QtCore, QtGui, QtXml")
 
 lxqt_translate_ts(QTERMWIDGET_QM
     TRANSLATION_DIR "lib/translations"
@@ -147,13 +143,12 @@ lxqt_translate_ts(QTERMWIDGET_QM
 )
 
 add_library(${QTERMWIDGET_LIBRARY_NAME} SHARED ${SRCS} ${MOCS} ${UI_SRCS} ${QTERMWIDGET_QM})
-target_link_libraries(${QTERMWIDGET_LIBRARY_NAME} Qt5::Widgets)
+target_link_libraries(${QTERMWIDGET_LIBRARY_NAME} Qt4::QtCore Qt4::QtGui Qt4::QtXml)
 set_target_properties( ${QTERMWIDGET_LIBRARY_NAME} PROPERTIES
                        SOVERSION ${QTERMWIDGET_VERSION_MAJOR}
                        VERSION ${QTERMWIDGET_VERSION}
                      )
 
-
 if(APPLE)
     target_compile_definitions(${QTERMWIDGET_LIBRARY_NAME}
         PRIVATE
@@ -210,7 +205,6 @@ target_compile_definitions(${QTERMWIDGET_LIBRARY_NAME}
         "HAVE_SYS_TIME_H"
 )
 
-
 generate_export_header(${QTERMWIDGET_LIBRARY_NAME}
     EXPORT_FILE_NAME "${CMAKE_CURRENT_BINARY_DIR}/lib/qtermwidget_export.h"
     BASE_NAME QTERMWIDGET
diff --git a/cmake/qtermwidget4-config.cmake.in b/cmake/qtermwidget4-config.cmake.in
new file mode 100644
index 0000000..e6c9b7b
--- /dev/null
+++ b/cmake/qtermwidget4-config.cmake.in
@@ -0,0 +1,20 @@
+# - Find the QTermWidget include and library
+#
+# Typical usage:
+#    find_package(QTermWidget4 REQUIRED)
+#
+#    add_executable(foo main.cpp)
+#    target_link_libraries(foo qtermwidget4)
+
+@PACKAGE_INIT@
+
+if (CMAKE_VERSION VERSION_LESS 3.0.2)
+    message(FATAL_ERROR \"qtermwidget requires at least CMake version 3.0.2\")
+endif()
+
+if (NOT TARGET @QTERMWIDGET_LIBRARY_NAME@)
+    if (POLICY CMP0024)
+        cmake_policy(SET CMP0024 NEW)
+    endif()
+    include("${CMAKE_CURRENT_LIST_DIR}/@QTERMWIDGET_LIBRARY_NAME@-targets.cmake")
+endif()
diff --git a/lib/ColorScheme.cpp b/lib/ColorScheme.cpp
index 6af2058..7e5b4dd 100644
--- a/lib/ColorScheme.cpp
+++ b/lib/ColorScheme.cpp
@@ -30,8 +30,7 @@
 #include <QtDebug>
 #include <QSettings>
 #include <QDir>
-#include <QRegularExpression>
-#include <QRandomGenerator>
+#include <QRegExp>
 
 
 // KDE
@@ -176,21 +175,25 @@ void ColorScheme::setColorTableEntry(int index , const ColorEntry& entry)
 
     _table[index] = entry;
 }
-ColorEntry ColorScheme::colorEntry(int index) const
+ColorEntry ColorScheme::colorEntry(int index , uint randomSeed) const
 {
     Q_ASSERT( index >= 0 && index < TABLE_COLORS );
 
+    if ( randomSeed != 0 )
+        qsrand(randomSeed);
+
     ColorEntry entry = colorTable()[index];
 
-    if ( _randomTable != nullptr &&
+    if ( randomSeed != 0 &&
+        _randomTable != nullptr &&
         !_randomTable[index].isNull() )
     {
         const RandomizationRange& range = _randomTable[index];
 
 
-        int hueDifference = range.hue ? QRandomGenerator::global()->bounded(range.hue) - range.hue/2 : 0;
-        int saturationDifference = range.saturation ? QRandomGenerator::global()->bounded(range.saturation) - range.saturation/2 : 0;
-        int valueDifference = range.value ? QRandomGenerator::global()->bounded(range.value) - range.value/2 : 0;
+        int hueDifference = range.hue ? (qrand() % range.hue) - range.hue/2 : 0;
+        int saturationDifference = range.saturation ? (qrand() % range.saturation) - range.saturation/2 : 0;
+        int  valueDifference = range.value ? (qrand() % range.value) - range.value/2 : 0;
 
         QColor& color = entry.color;
 
@@ -203,10 +206,10 @@ ColorEntry ColorScheme::colorEntry(int index) const
 
     return entry;
 }
-void ColorScheme::getColorTable(ColorEntry* table) const
+void ColorScheme::getColorTable(ColorEntry* table , uint randomSeed) const
 {
     for ( int i = 0 ; i < TABLE_COLORS ; i++ )
-        table[i] = colorEntry(i);
+        table[i] = colorEntry(i,randomSeed);
 }
 bool ColorScheme::randomizedBackgroundColor() const
 {
@@ -342,7 +345,7 @@ void ColorScheme::readColorEntry(QSettings * s , int index)
     if (colorValue.type() == QVariant::StringList)
     {
         QStringList rgbList = colorValue.toStringList();
-        colorStr = rgbList.join(QLatin1Char(','));
+        colorStr = rgbList.join(QString::fromAscii(","));
         if (rgbList.count() == 3)
         {
             bool parse_ok;
@@ -359,14 +362,13 @@ void ColorScheme::readColorEntry(QSettings * s , int index)
     else
     {
         colorStr = colorValue.toString();
-        QRegularExpression hexColorPattern(QLatin1String("^#[0-9a-f]{6}$"),
-                                           QRegularExpression::CaseInsensitiveOption);
-        if (hexColorPattern.match(colorStr).hasMatch())
+        QRegExp hexColorPattern(QString::fromAscii("^#[0-9a-f]{6}$"), Qt::CaseInsensitive);
+        if (hexColorPattern.indexIn(colorStr) >= 0)
         {
             // Parsing is always ok as already matched by the regexp
-            r = colorStr.midRef(1, 2).toInt(nullptr, 16);
-            g = colorStr.midRef(3, 2).toInt(nullptr, 16);
-            b = colorStr.midRef(5, 2).toInt(nullptr, 16);
+            r = colorStr.mid(1, 2).toInt(0, 16);
+            g = colorStr.mid(3, 2).toInt(0, 16);
+            b = colorStr.mid(5, 2).toInt(0, 16);
             ok = true;
         }
     }
@@ -670,5 +672,5 @@ const ColorScheme* ColorSchemeManager::findColorScheme(const QString& name)
 Q_GLOBAL_STATIC(ColorSchemeManager, theColorSchemeManager)
 ColorSchemeManager* ColorSchemeManager::instance()
 {
-    return theColorSchemeManager;
+    return theColorSchemeManager();
 }
diff --git a/lib/ColorScheme.h b/lib/ColorScheme.h
index a7ed57e..afd7c35 100644
--- a/lib/ColorScheme.h
+++ b/lib/ColorScheme.h
@@ -87,14 +87,14 @@ public:
      * @param randomSeed Color schemes may allow certain colors in their
      * palette to be randomized.  The seed is used to pick the random color.
      */
-    void getColorTable(ColorEntry* table) const;
+    void getColorTable(ColorEntry* table, uint randomSeed = 0) const;
 
     /**
      * Retrieves a single color entry from the table.
      *
      * See getColorTable()
      */
-    ColorEntry colorEntry(int index) const;
+    ColorEntry colorEntry(int index , uint randomSeed = 0) const;
 
     /**
      * Convenience method.  Returns the
diff --git a/lib/Emulation.cpp b/lib/Emulation.cpp
index 723f5d2..00ecb66 100644
--- a/lib/Emulation.cpp
+++ b/lib/Emulation.cpp
@@ -72,10 +72,14 @@ Emulation::Emulation() :
   connect(this , SIGNAL(programBracketedPasteModeChanged(bool)) ,
            SLOT(bracketedPasteModeChanged(bool)));
 
-  connect(this, &Emulation::cursorChanged, this, [this] (KeyboardCursorShape cursorShape, bool blinkingCursorEnabled) {
-    emit titleChanged( 50, QString(QLatin1String("CursorShape=%1;BlinkingCursorEnabled=%2"))
-                               .arg(static_cast<int>(cursorShape)).arg(blinkingCursorEnabled) );
-  });
+  connect(this, SIGNAL(cursorChanged(KeyboardCursorShape,bool)),
+           this, SLOT(onCursorChanged(KeyboardCursorShape,bool)));
+}
+
+void Emulation::onCursorChanged(KeyboardCursorShape cursorShape, bool blinkingCursorEnabled)
+{
+    emit titleChanged(50, QString::fromAscii("CursorShape=%1;BlinkingCursorEnabled=%2")
+                      .arg(static_cast<int>(cursorShape)).arg(blinkingCursorEnabled));
 }
 
 bool Emulation::programUsesMouse() const
@@ -104,16 +108,16 @@ ScreenWindow* Emulation::createWindow()
     window->setScreen(_currentScreen);
     _windows << window;
 
-    connect(window , SIGNAL(selectionChanged()),
-            this , SLOT(bufferedUpdate()));
+    connect(window, SIGNAL(selectionChanged()),
+            this, SLOT(bufferedUpdate()));
 
-    connect(this , SIGNAL(outputChanged()),
-            window , SLOT(notifyOutputChanged()) );
+    connect(this, SIGNAL(outputChanged()),
+            window, SLOT(notifyOutputChanged()) );
 
-    connect(this, &Emulation::handleCommandFromKeyboard,
-            window, &ScreenWindow::handleCommandFromKeyboard);
-    connect(this, &Emulation::outputFromKeypressEvent,
-            window, &ScreenWindow::scrollToEnd);
+    connect(this, SIGNAL(handleCommandFromKeyboard(QByteArray)),
+            window, SLOT(handleCommandFromKeyboard(QByteArray)));
+    connect(this, SIGNAL(outputFromKeypressEvent()),
+            window, SLOT(scrollToEnd()));
 
     return window;
 }
@@ -139,7 +143,7 @@ void Emulation::setScreen(int n)
   if (_currentScreen != old)
   {
      // tell all windows onto this emulation to switch to the newly active screen
-     for(ScreenWindow* window : qAsConst(_windows))
+     for(ScreenWindow* window : const_cast<const QList<ScreenWindow*>&>(_windows))
          window->setScreen(_currentScreen);
   }
 }
diff --git a/lib/Emulation.h b/lib/Emulation.h
index 7d2263b..9c4f581 100644
--- a/lib/Emulation.h
+++ b/lib/Emulation.h
@@ -128,7 +128,7 @@ public:
    * This enum describes the available shapes for the keyboard cursor.
    * See setKeyboardCursorShape()
    */
-  enum class KeyboardCursorShape {
+  enum KeyboardCursorShape {
       /** A rectangular block which covers the entire area of the cursor character. */
       BlockCursor = 0,
       /**
@@ -445,6 +445,9 @@ signals:
   void handleCommandFromKeyboard(KeyboardTranslator::Command command);
   void outputFromKeypressEvent(void);
 
+public slots:
+  void onCursorChanged(KeyboardCursorShape cursorShape, bool blinkingCursorEnabled);
+
 protected:
   virtual void setMode(int mode) = 0;
   virtual void resetMode(int mode) = 0;
diff --git a/lib/Filter.cpp b/lib/Filter.cpp
index f219292..c8d6396 100644
--- a/lib/Filter.cpp
+++ b/lib/Filter.cpp
@@ -402,7 +402,7 @@ RegExpFilter::HotSpot* UrlFilter::newHotSpot(int startLine,int startColumn,int e
 {
     HotSpot *spot = new UrlFilter::HotSpot(startLine,startColumn,
                                                endLine,endColumn);
-    connect(spot->getUrlObject(), &FilterObject::activated, this, &UrlFilter::activated);
+    connect(spot->getUrlObject(), SIGNAL(activated(QUrl,bool)), this, SLOT(activated(QUrl,bool)));
     return spot;
 }
 
@@ -415,7 +415,7 @@ UrlFilter::HotSpot::HotSpot(int startLine,int startColumn,int endLine,int endCol
 
 UrlFilter::HotSpot::UrlType UrlFilter::HotSpot::urlType() const
 {
-    QString url = capturedTexts().constFirst();
+    QString url = capturedTexts().at(0);
 
     if ( FullUrlRegExp.exactMatch(url) )
         return StandardUrl;
@@ -427,7 +427,7 @@ UrlFilter::HotSpot::UrlType UrlFilter::HotSpot::urlType() const
 
 void UrlFilter::HotSpot::activate(const QString& actionName)
 {
-    QString url = capturedTexts().constFirst();
+    QString url = capturedTexts().at(0);
 
     const UrlType kind = urlType();
 
@@ -524,11 +524,11 @@ QList<QAction*> UrlFilter::HotSpot::actions()
     // object names are set here so that the hotspot performs the
     // correct action when activated() is called with the triggered
     // action passed as a parameter.
-    openAction->setObjectName( QLatin1String("open-action" ));
-    copyAction->setObjectName( QLatin1String("copy-action" ));
+    openAction->setObjectName(QLatin1String("open-action"));
+    copyAction->setObjectName(QLatin1String("copy-action"));
 
-    QObject::connect( openAction , &QAction::triggered , _urlObject , &FilterObject::activate );
-    QObject::connect( copyAction , &QAction::triggered , _urlObject , &FilterObject::activate );
+    QObject::connect(openAction, SIGNAL(triggered()), _urlObject, SLOT(activate()));
+    QObject::connect(copyAction, SIGNAL(triggered()), _urlObject, SLOT(activate()));
 
     list << openAction;
     list << copyAction;
diff --git a/lib/Filter.h b/lib/Filter.h
index 3d8d4b7..be6baee 100644
--- a/lib/Filter.h
+++ b/lib/Filter.h
@@ -244,6 +244,7 @@ class FilterObject;
 class QTERMWIDGET_EXPORT UrlFilter : public RegExpFilter
 {
     Q_OBJECT
+
 public:
     /**
      * Hotspot type created by UrlFilter instances.  The activate() method opens a web browser
@@ -282,31 +283,35 @@ public:
 
     UrlFilter();
 
+signals:
+    void activated(const QUrl& url, bool fromContextMenu);
+
 protected:
     RegExpFilter::HotSpot* newHotSpot(int,int,int,int) override;
 
 private:
-
     static const QRegExp FullUrlRegExp;
     static const QRegExp EmailAddressRegExp;
 
     // combined OR of FullUrlRegExp and EmailAddressRegExp
     static const QRegExp CompleteUrlRegExp;
-signals:
-    void activated(const QUrl& url, bool fromContextMenu);
 };
 
 class QTERMWIDGET_NO_EXPORT FilterObject : public QObject
 {
     Q_OBJECT
+
 public:
     FilterObject(Filter::HotSpot* filter) : _filter(filter) {}
 
     void emitActivated(const QUrl& url, bool fromContextMenu);
+
 public slots:
     void activate();
+
 private:
     Filter::HotSpot* _filter;
+
 signals:
     void activated(const QUrl& url, bool fromContextMenu);
 };
diff --git a/lib/KeyboardTranslator.cpp b/lib/KeyboardTranslator.cpp
index e0f2833..3499b8a 100644
--- a/lib/KeyboardTranslator.cpp
+++ b/lib/KeyboardTranslator.cpp
@@ -249,7 +249,7 @@ KeyboardTranslatorReader::KeyboardTranslatorReader( QIODevice* source )
    // read input until we find the description
    while ( _description.isEmpty() && !source->atEnd() )
    {
-        QList<Token> tokens = tokenize( QString::fromUtf8(source->readLine()) );
+        QList<Token> tokens = tokenize( QString::fromUtf8(source->readLine().constData()) );
         if ( !tokens.isEmpty() && tokens.first().type == Token::TitleKeyword )
             _description = tokens[1].text;
    }
@@ -261,7 +261,7 @@ void KeyboardTranslatorReader::readNext()
     // find next entry
     while ( !_source->atEnd() )
     {
-        const QList<Token>& tokens = tokenize( QString::fromUtf8(_source->readLine()) );
+        const QList<Token>& tokens = tokenize( QString::fromUtf8(_source->readLine().constData()) );
         if ( !tokens.isEmpty() && tokens.first().type == Token::KeyKeyword )
         {
             KeyboardTranslator::States flags = KeyboardTranslator::NoState;
@@ -787,7 +787,7 @@ void KeyboardTranslator::Entry::insertState( QString& item , int state ) const
 QString KeyboardTranslator::Entry::resultToString(bool expandWildCards,Qt::KeyboardModifiers modifiers) const
 {
     if ( !_text.isEmpty() )
-        return QString::fromLatin1(escapedText(expandWildCards,modifiers));
+        return QString::fromLatin1(escapedText(expandWildCards,modifiers).constData());
     else if ( _command == EraseCommand )
         return QLatin1String("Erase");
     else if ( _command == ScrollPageUpCommand )
@@ -871,7 +871,7 @@ void KeyboardTranslator::removeEntry(const Entry& entry)
 }
 KeyboardTranslator::Entry KeyboardTranslator::findEntry(int keyCode, Qt::KeyboardModifiers modifiers, States state) const
 {
-    for (auto it = _entries.cbegin(), end = _entries.cend(); it != end; ++it)
+    for (auto it = _entries.constBegin(), end = _entries.constEnd(); it != end; ++it)
     {
         if (it.key() == keyCode)
             if ( it.value().matches(keyCode,modifiers,state) )
@@ -907,5 +907,5 @@ bool KeyboardTranslatorManager::deleteTranslator(const QString& name)
 Q_GLOBAL_STATIC( KeyboardTranslatorManager , theKeyboardTranslatorManager )
 KeyboardTranslatorManager* KeyboardTranslatorManager::instance()
 {
-    return theKeyboardTranslatorManager;
+    return theKeyboardTranslatorManager();
 }
diff --git a/lib/Pty.cpp b/lib/Pty.cpp
index 75a23a1..8203f64 100644
--- a/lib/Pty.cpp
+++ b/lib/Pty.cpp
@@ -156,7 +156,7 @@ void Pty::addEnvironmentVariables(const QStringList& environment)
 
     // fallback to ensure that $TERM is always set
     if (!termEnvVarAdded) {
-        setEnv(QStringLiteral("TERM"), QStringLiteral("xterm-256color"));
+        setEnv(QString::fromUtf8("TERM"), QString::fromUtf8("xterm-256color"));
     }
 }
 }
diff --git a/lib/SearchBar.cpp b/lib/SearchBar.cpp
index 1de92f4..04c4d84 100644
--- a/lib/SearchBar.cpp
+++ b/lib/SearchBar.cpp
@@ -27,7 +27,7 @@ SearchBar::SearchBar(QWidget *parent) : QWidget(parent)
 {
     widget.setupUi(this);
     setAutoFillBackground(true); // make it always opaque, especially inside translucent windows
-    connect(widget.closeButton, &QAbstractButton::clicked, this, &SearchBar::hide);
+    connect(widget.closeButton, SIGNAL(clicked()), this, SLOT(hide()));
     connect(widget.searchTextEdit, SIGNAL(textChanged(QString)), this, SIGNAL(searchCriteriaChanged()));
     connect(widget.findPreviousButton, SIGNAL(clicked()), this, SIGNAL(findPrevious()));
     connect(widget.findNextButton, SIGNAL(clicked()), this, SIGNAL(findNext()));
@@ -43,9 +43,9 @@ SearchBar::SearchBar(QWidget *parent) : QWidget(parent)
     connect(m_matchCaseMenuEntry, SIGNAL(toggled(bool)), this, SIGNAL(searchCriteriaChanged()));
 
 
-    m_useRegularExpressionMenuEntry = optionsMenu->addAction(tr("Regular expression"));
-    m_useRegularExpressionMenuEntry->setCheckable(true);
-    connect(m_useRegularExpressionMenuEntry, SIGNAL(toggled(bool)), this, SIGNAL(searchCriteriaChanged()));
+    m_useRegExpMenuEntry = optionsMenu->addAction(tr("Regular expression"));
+    m_useRegExpMenuEntry->setCheckable(true);
+    connect(m_useRegExpMenuEntry, SIGNAL(toggled(bool)), this, SIGNAL(searchCriteriaChanged()));
 
     m_highlightMatchesMenuEntry = optionsMenu->addAction(tr("Highlight all matches"));
     m_highlightMatchesMenuEntry->setCheckable(true);
@@ -62,9 +62,9 @@ QString SearchBar::searchText()
 }
 
 
-bool SearchBar::useRegularExpression()
+bool SearchBar::useRegExp()
 {
-    return m_useRegularExpressionMenuEntry->isChecked();
+    return m_useRegExpMenuEntry->isChecked();
 }
 
 bool SearchBar::matchCase()
diff --git a/lib/SearchBar.h b/lib/SearchBar.h
index 1200884..9746a92 100644
--- a/lib/SearchBar.h
+++ b/lib/SearchBar.h
@@ -31,7 +31,7 @@ public:
     ~SearchBar() override;
     virtual void show();
     QString searchText();
-    bool useRegularExpression();
+    bool useRegExp();
     bool matchCase();
     bool highlightAllMatches();
 
@@ -54,7 +54,7 @@ private slots:
 private:
     Ui::SearchBar widget;
     QAction *m_matchCaseMenuEntry;
-    QAction *m_useRegularExpressionMenuEntry;
+    QAction *m_useRegExpMenuEntry;
     QAction *m_highlightMatchesMenuEntry;
 };
 
diff --git a/lib/Session.cpp b/lib/Session.cpp
index a40f998..f376d22 100644
--- a/lib/Session.cpp
+++ b/lib/Session.cpp
@@ -92,15 +92,15 @@ Session::Session(QObject* parent) :
 //            SLOT( fireZModemDetected() ) );
     connect( _emulation, SIGNAL( changeTabTextColorRequest( int ) ),
              this, SIGNAL( changeTabTextColorRequest( int ) ) );
-    connect( _emulation, SIGNAL(profileChangeCommandReceived(const QString &)),
+    connect( _emulation, SIGNAL( profileChangeCommandReceived(const QString &) ),
              this, SIGNAL( profileChangeCommandReceived(const QString &)) );
 
     connect(_emulation, SIGNAL(imageResizeRequest(QSize)),
             this, SLOT(onEmulationSizeChange(QSize)));
     connect(_emulation, SIGNAL(imageSizeChanged(int, int)),
             this, SLOT(onViewSizeChange(int, int)));
-    connect(_emulation, &Vt102Emulation::cursorChanged,
-            this, &Session::cursorChanged);
+    connect(_emulation, SIGNAL(cursorChanged(Konsole::Emulation::KeyboardCursorShape,bool)), 
+            this, SLOT(cursorChanged(Konsole::Emulation::KeyboardCursorShape,bool)));
 
     //connect teletype to emulation backend
     _shellProcess->setUtf8Mode(_emulation->utf8());
@@ -174,8 +174,8 @@ void Session::addView(TerminalDisplay * widget)
 
     if ( _emulation != nullptr ) {
         // connect emulation - view signals and slots
-        connect( widget , &TerminalDisplay::keyPressedSignal, _emulation ,
-                 &Emulation::sendKeyEvent);
+        connect( widget , SIGNAL(keyPressedSignal(QKeyEvent*,bool)), _emulation ,
+                 SLOT(sendKeyEvent(QKeyEvent*,bool)) );
         connect( widget , SIGNAL(mouseSignal(int,int,int,int)) , _emulation ,
                  SLOT(sendMouseEvent(int,int,int,int)) );
         connect( widget , SIGNAL(sendStringToEmu(const char *)) , _emulation ,
@@ -252,7 +252,7 @@ void Session::run()
      * As far as i know /bin/sh exists on every unix system.. You could also just put some ifdef __FREEBSD__ here but i think these 2 filechecks are worth
      * their computing time on any system - especially with the problem on arch linux being there too.
      */
-    QString exec = QString::fromLocal8Bit(QFile::encodeName(_program));
+    QString exec = QString::fromLocal8Bit(QFile::encodeName(_program).constData());
     // if 'exec' is not specified, fall back to default shell.  if that
     // is not set then fall back to /bin/sh
 
@@ -264,7 +264,7 @@ void Session::run()
 
         QFile excheck(exec);
         if ( exec.isEmpty() || !excheck.exists() ) {
-            exec = QString::fromLocal8Bit(qgetenv("SHELL"));
+            exec = QString::fromLocal8Bit(qgetenv("SHELL").constData());
         }
         excheck.setFileName(exec);
 
@@ -276,7 +276,7 @@ void Session::run()
 
     // _arguments sometimes contain ("") so isEmpty()
     // or count() does not work as expected...
-    QString argsTmp(_arguments.join(QLatin1Char(' ')).trimmed());
+    QString argsTmp(_arguments.join(QString::fromAscii(" ")).trimmed());
     QStringList arguments;
     arguments << exec;
     if (argsTmp.length())
@@ -539,7 +539,7 @@ void Session::refresh()
 
 bool Session::sendSignal(int signal)
 {
-    int result = ::kill(static_cast<pid_t>(_shellProcess->processId()),signal);
+    int result = ::kill(_shellProcess->pid(),signal);
 
      if ( result == 0 )
      {
@@ -928,7 +928,7 @@ int Session::foregroundProcessId() const
 }
 int Session::processId() const
 {
-    return static_cast<int>(_shellProcess->processId());
+    return _shellProcess->pid();
 }
 int Session::getPtySlaveFd() const
 {
diff --git a/lib/ShellCommand.cpp b/lib/ShellCommand.cpp
index 03afa45..ff7cd7d 100644
--- a/lib/ShellCommand.cpp
+++ b/lib/ShellCommand.cpp
@@ -67,7 +67,7 @@ ShellCommand::ShellCommand(const QString & command , const QStringList & argumen
 }
 QString ShellCommand::fullCommand() const
 {
-    return _arguments.join(QLatin1Char(' '));
+    return _arguments.join(QString::fromAscii(" "));
 }
 QString ShellCommand::command() const
 {
@@ -152,7 +152,7 @@ static bool expandEnv( QString & text )
                 int len = pos2 - pos;
                 QString key = text.mid( pos+1, len-1);
                 QString value =
-                    QString::fromLocal8Bit( qgetenv(key.toLocal8Bit().constData()) );
+                    QString::fromLocal8Bit( qgetenv(key.toLocal8Bit().constData()).constData() );
 
                 if ( !value.isEmpty() ) {
                     expanded = true;
diff --git a/lib/TerminalDisplay.cpp b/lib/TerminalDisplay.cpp
index 2fb3089..1399c32 100644
--- a/lib/TerminalDisplay.cpp
+++ b/lib/TerminalDisplay.cpp
@@ -38,7 +38,7 @@
 #include <QMessageBox>
 #include <QPainter>
 #include <QPixmap>
-#include <QRegularExpression>
+#include <QRegExp>
 #include <QScrollBar>
 #include <QStyle>
 #include <QTimer>
@@ -145,7 +145,7 @@ void TerminalDisplay::setScreenWindow(ScreenWindow* window)
         connect( _screenWindow , SIGNAL(outputChanged()) , this , SLOT(updateImage()) );
         connect( _screenWindow , SIGNAL(outputChanged()) , this , SLOT(updateFilters()) );
         connect( _screenWindow , SIGNAL(scrolled(int)) , this , SLOT(updateFilters()) );
-        connect( _screenWindow , &ScreenWindow::scrollToEnd , this , &TerminalDisplay::scrollToEnd );
+        connect( _screenWindow , SIGNAL(scrollToEnd()) , this , SLOT(scrollToEnd()));
         window->setWindowLines(_lines);
     }
 }
@@ -226,14 +226,14 @@ void TerminalDisplay::fontChange(const QFont&)
   // "Base character width on widest ASCII character. This prevents too wide
   //  characters in the presence of double wide (e.g. Japanese) characters."
   // Get the width from representative normal width characters
-  _fontWidth = qRound(static_cast<double>(fm.horizontalAdvance(QLatin1String(REPCHAR)))/static_cast<double>(qstrlen(REPCHAR)));
+  _fontWidth = qRound(static_cast<double>(fm.width(QLatin1String(REPCHAR)))/static_cast<double>(qstrlen(REPCHAR)));
 
   _fixedFont = true;
 
-  int fw = fm.horizontalAdvance(QLatin1Char(REPCHAR[0]));
+  int fw = fm.width(QLatin1Char(REPCHAR[0]));
   for(unsigned int i=1; i< qstrlen(REPCHAR); i++)
   {
-    if (fw != fm.horizontalAdvance(QLatin1Char(REPCHAR[i])))
+    if (fw != fm.width(QLatin1Char(REPCHAR[i])))
     {
       _fixedFont = false;
       break;
@@ -386,8 +386,7 @@ TerminalDisplay::TerminalDisplay(QWidget *parent)
   _scrollBar = new QScrollBar(this);
   // since the contrast with the terminal background may not be enough,
   // the scrollbar should be auto-filled if not transient
-  if (!_scrollBar->style()->styleHint(QStyle::SH_ScrollBar_Transient, nullptr, _scrollBar))
-    _scrollBar->setAutoFillBackground(true);
+  _scrollBar->setAutoFillBackground(true);
   setScroll(0,0);
   _scrollBar->setCursor( Qt::ArrowCursor );
   connect(_scrollBar, SIGNAL(valueChanged(int)), this,
@@ -956,9 +955,7 @@ void TerminalDisplay::scrollImage(int lines , const QRect& screenWindowRegion)
     // Set the QT_FLUSH_PAINT environment variable to '1' before starting the
     // application to monitor repainting.
     //
-    int scrollBarWidth = _scrollBar->isHidden() ? 0 :
-                         _scrollBar->style()->styleHint(QStyle::SH_ScrollBar_Transient, nullptr, _scrollBar) ?
-                         0 : _scrollBar->width();
+    int scrollBarWidth = _scrollBar->isHidden() ? 0 : _scrollBar->width();
     const int SCROLLBAR_CONTENT_GAP = scrollBarWidth == 0 ? 0 : 1;
     QRect scrollRect;
     if ( _scrollbarLocation == QTermWidget::ScrollBarLeft )
@@ -1274,7 +1271,7 @@ void TerminalDisplay::showResizeNotification()
      {
          const QString label = tr("Size: XXX x XXX");
         _resizeWidget = new QLabel(label, this);
-        _resizeWidget->setMinimumWidth(_resizeWidget->fontMetrics().horizontalAdvance(label));
+        _resizeWidget->setMinimumWidth(_resizeWidget->fontMetrics().width(label));
         _resizeWidget->setMinimumHeight(_resizeWidget->sizeHint().height());
         _resizeWidget->setAlignment(Qt::AlignCenter);
 
@@ -1443,11 +1440,11 @@ void TerminalDisplay::paintEvent( QPaintEvent* pe )
   }
 
   const QRegion regToDraw = pe->region() & cr;
-  for (auto rect = regToDraw.begin(); rect != regToDraw.end(); rect++)
+  foreach (const QRect &rect, regToDraw.rects())
   {
-    drawBackground(paint,*rect,palette().window().color(),
+    drawBackground(paint, rect, palette().window().color(),
                    true /* use opacity setting */);
-    drawContents(paint, *rect);
+    drawContents(paint, rect);
   }
   drawInputMethodPreeditString(paint,preeditRect());
   paintFilters(paint);
@@ -1506,8 +1503,7 @@ void TerminalDisplay::paintFilters(QPainter& painter)
     int cursorLine;
     int cursorColumn;
     int leftMargin = _leftBaseMargin
-                     + ((_scrollbarLocation == QTermWidget::ScrollBarLeft
-                         && !_scrollBar->style()->styleHint(QStyle::SH_ScrollBar_Transient, nullptr, _scrollBar))
+                     + ((_scrollbarLocation == QTermWidget::ScrollBarLeft)
                         ? _scrollBar->width() : 0);
 
     getCharacterPosition( cursorPos , cursorLine , cursorColumn );
@@ -1619,7 +1615,7 @@ int TerminalDisplay::textWidth(const int startColumn, const int length, const in
   QFontMetrics fm(font());
   int result = 0;
   for (int column = 0; column < length; column++) {
-    result += fm.horizontalAdvance(_image[loc(startColumn + column, line)].character);
+    result += fm.width(_image[loc(startColumn + column, line)].character);
   }
   return result;
 }
@@ -2014,7 +2010,7 @@ void TerminalDisplay::mousePressEvent(QMouseEvent* ev)
           spot->activate(QLatin1String("click-action"));
     }
   }
-  else if ( ev->button() == Qt::MiddleButton )
+  else if ( ev->button() == Qt::MidButton )
   {
     if ( _mouseMarks || (ev->modifiers() & Qt::ShiftModifier) )
       emitSelection(true,ev->modifiers() & Qt::ControlModifier);
@@ -2045,8 +2041,7 @@ void TerminalDisplay::mouseMoveEvent(QMouseEvent* ev)
   int charLine = 0;
   int charColumn = 0;
   int leftMargin = _leftBaseMargin
-                   + ((_scrollbarLocation == QTermWidget::ScrollBarLeft
-                       && !_scrollBar->style()->styleHint(QStyle::SH_ScrollBar_Transient, nullptr, _scrollBar))
+                   + ((_scrollbarLocation == QTermWidget::ScrollBarLeft)
                       ? _scrollBar->width() : 0);
 
   getCharacterPosition(ev->pos(),charLine,charColumn);
@@ -2105,7 +2100,7 @@ void TerminalDisplay::mouseMoveEvent(QMouseEvent* ev)
     int button = 3;
     if (ev->buttons() & Qt::LeftButton)
         button = 0;
-    if (ev->buttons() & Qt::MiddleButton)
+    if (ev->buttons() & Qt::MidButton)
         button = 1;
     if (ev->buttons() & Qt::RightButton)
         button = 2;
@@ -2147,7 +2142,7 @@ void TerminalDisplay::mouseMoveEvent(QMouseEvent* ev)
   if (_actSel == 0) return;
 
  // don't extend selection while pasting
-  if (ev->buttons() & Qt::MiddleButton) return;
+  if (ev->buttons() & Qt::MidButton) return;
 
   extendSelection( ev->pos() );
 }
@@ -2402,9 +2397,9 @@ void TerminalDisplay::mouseReleaseEvent(QMouseEvent* ev)
 
   if ( !_mouseMarks &&
        ((ev->button() == Qt::RightButton && !(ev->modifiers() & Qt::ShiftModifier))
-                        || ev->button() == Qt::MiddleButton) )
+                        || ev->button() == Qt::MidButton) )
   {
-    emit mouseSignal( ev->button() == Qt::MiddleButton ? 1 : 2,
+    emit mouseSignal( ev->button() == Qt::MidButton ? 1 : 2,
                       charColumn + 1,
                       charLine + 1 +_scrollBar->value() -_scrollBar->maximum() ,
                       2);
@@ -2549,7 +2544,7 @@ void TerminalDisplay::mouseDoubleClickEvent(QMouseEvent* ev)
 
 void TerminalDisplay::wheelEvent( QWheelEvent* ev )
 {
-  if (ev->angleDelta().y() == 0)
+  if (ev->delta() == 0)
     return;
 
   // if the terminal program is not interested mouse events
@@ -2569,10 +2564,10 @@ void TerminalDisplay::wheelEvent( QWheelEvent* ev )
         // to get a reasonable scrolling speed, scroll by one line for every 5 degrees
         // of mouse wheel rotation.  Mouse wheels typically move in steps of 15 degrees,
         // giving a scroll of 3 lines
-        int key = ev->angleDelta().y() > 0 ? Qt::Key_Up : Qt::Key_Down;
+        int key = ev->delta() > 0 ? Qt::Key_Up : Qt::Key_Down;
 
         // QWheelEvent::angleDelta().y() gives rotation in eighths of a degree
-        int wheelDegrees = ev->angleDelta().y() / 8;
+        int wheelDegrees = ev->delta() / 8;
         int linesToScroll = abs(wheelDegrees) / 5;
 
         QKeyEvent keyScrollEvent(QEvent::KeyPress,key,Qt::NoModifier);
@@ -2587,9 +2582,9 @@ void TerminalDisplay::wheelEvent( QWheelEvent* ev )
 
     int charLine;
     int charColumn;
-    getCharacterPosition( ev->position() , charLine , charColumn );
+    getCharacterPosition(ev->pos(), charLine, charColumn);
 
-    emit mouseSignal( ev->angleDelta().y() > 0 ? 4 : 5,
+    emit mouseSignal(ev->delta() > 0 ? 4 : 5,
                       charColumn + 1,
                       charLine + 1 +_scrollBar->value() -_scrollBar->maximum() ,
                       0);
@@ -2729,7 +2724,7 @@ void TerminalDisplay::emitSelection(bool useXselection,bool appendReturn)
     text.replace(QLatin1Char('\n'), QLatin1Char('\r'));
 
     if (_trimPastedTrailingNewlines) {
-        text.replace(QRegularExpression(QStringLiteral("\\r+$")), QString());
+        text.replace(QRegExp(QString::fromAscii("\\r+$")), QString());
     }
 
     if (_confirmMultilinePaste && text.contains(QLatin1Char('\r'))) {
@@ -2792,7 +2787,7 @@ bool TerminalDisplay::multilineConfirmation(const QString& text)
     const auto buttons = confirmation.buttons();
     for( QAbstractButton * btn : buttons ) {
         if (confirmation.buttonRole(btn) == QMessageBox::ActionRole && btn->text() == QMessageBox::tr("Show Details...")) {
-            Q_EMIT btn->clicked();
+            btn->animateClick();
             break;
         }
     }
@@ -2901,7 +2896,7 @@ QVariant TerminalDisplay::inputMethodQuery( Qt::InputMethodQuery query ) const
     const QPoint cursorPos = _screenWindow ? _screenWindow->cursorPosition() : QPoint(0,0);
     switch ( query )
     {
-        case Qt::ImCursorRectangle:
+        case Qt::ImMicroFocus:
                 return imageToWidget(QRect(cursorPos.x(),cursorPos.y(),1,1));
             break;
         case Qt::ImFont:
@@ -3070,8 +3065,7 @@ void TerminalDisplay::clearImage()
 void TerminalDisplay::calcGeometry()
 {
   _scrollBar->resize(_scrollBar->sizeHint().width(), contentsRect().height());
-  int scrollBarWidth = _scrollBar->style()->styleHint(QStyle::SH_ScrollBar_Transient, nullptr, _scrollBar)
-                       ? 0 : _scrollBar->width();
+  int scrollBarWidth = _scrollBar->width();
   switch(_scrollbarLocation)
   {
     case QTermWidget::NoScrollBar :
@@ -3126,8 +3120,7 @@ void TerminalDisplay::makeImage()
 // calculate the needed size, this must be synced with calcGeometry()
 void TerminalDisplay::setSize(int columns, int lines)
 {
-  int scrollBarWidth = (_scrollBar->isHidden()
-                        || _scrollBar->style()->styleHint(QStyle::SH_ScrollBar_Transient, nullptr, _scrollBar))
+  int scrollBarWidth = (_scrollBar->isHidden())
                        ? 0 : _scrollBar->sizeHint().width();
   int horizontalMargin = 2 * _leftBaseMargin;
   int verticalMargin = 2 * _topBaseMargin;
@@ -3220,7 +3213,7 @@ void TerminalDisplay::dropEvent(QDropEvent* event)
     dropText.replace(QLatin1Char('\n'), QLatin1Char('\r'));
     if (_trimPastedTrailingNewlines)
     {
-      dropText.replace(QRegularExpression(QStringLiteral("\\r+$")), QString());
+      dropText.replace(QRegExp(QString::fromAscii("\\r+$")), QString());
     }
     if (_confirmMultilinePaste && dropText.contains(QLatin1Char('\r')))
     {
@@ -3270,8 +3263,9 @@ void TerminalDisplay::outputSuspended(bool suspended)
             _outputSuspendedLabel->setContentsMargins(5, 5, 5, 5);
 
             //enable activation of "Xon/Xoff" link in label
-            _outputSuspendedLabel->setTextInteractionFlags(Qt::LinksAccessibleByMouse |
-                                                          Qt::LinksAccessibleByKeyboard);
+            _outputSuspendedLabel->setTextInteractionFlags(
+                Qt::TextInteractionFlags(Qt::LinksAccessibleByMouse | Qt::TextSelectableByMouse)
+            );
             _outputSuspendedLabel->setOpenExternalLinks(true);
             _outputSuspendedLabel->setVisible(false);
 
diff --git a/lib/Vt102Emulation.cpp b/lib/Vt102Emulation.cpp
index e74f882..cafb443 100644
--- a/lib/Vt102Emulation.cpp
+++ b/lib/Vt102Emulation.cpp
@@ -1091,7 +1091,7 @@ void Vt102Emulation::sendKeyEvent(QKeyEvent* event, bool fromPaste)
         }
         else if ( !entry.text().isEmpty() )
         {
-            textToSend += _codec->fromUnicode(QString::fromUtf8(entry.text(true,modifiers)));
+            textToSend += _codec->fromUnicode(QString::fromUtf8(entry.text(true,modifiers).constData()));
         }
         else if((modifiers & KeyboardTranslator::CTRL_MOD) && event->key() >= 0x40 && event->key() < 0x5f) {
             textToSend += (event->key() & 0x1f);
@@ -1369,8 +1369,6 @@ void Vt102Emulation::reportDecodingError()
 {
   if (tokenBufferPos == 0 || ( tokenBufferPos == 1 && (tokenBuffer[0] & 0xff) >= 32) )
     return;
-  qCDebug(qtermwidgetLogger) << "Undecodable sequence:" << QString::fromWCharArray(tokenBuffer, tokenBufferPos);
 }
 
 //#include "Vt102Emulation.moc"
-
diff --git a/lib/kprocess.cpp b/lib/kprocess.cpp
index 6e8406e..49f9ad5 100644
--- a/lib/kprocess.cpp
+++ b/lib/kprocess.cpp
@@ -50,7 +50,10 @@ KProcess::KProcess(KProcessPrivate *d, QObject *parent) :
     setOutputChannelMode(ForwardedChannels);
 }
 
-KProcess::~KProcess() = default;
+KProcess::~KProcess()
+{
+    delete d_ptr;
+}
 
 void KProcess::setOutputChannelMode(OutputChannelMode mode)
 {
@@ -308,3 +311,12 @@ int KProcess::startDetached(const QStringList &argv)
     QString prog = args.takeFirst();
     return startDetached(prog, args);
 }
+
+int KProcess::pid() const
+{
+#ifdef Q_OS_UNIX
+    return (int) QProcess::pid();
+#else
+    return QProcess::pid() ? QProcess::pid()->dwProcessId : 0;
+#endif
+}
diff --git a/lib/kprocess.h b/lib/kprocess.h
index 3dc4616..a3caf6c 100644
--- a/lib/kprocess.h
+++ b/lib/kprocess.h
@@ -34,8 +34,6 @@
 
 #include <QProcess>
 
-#include <memory>
-
 class KProcessPrivate;
 
 /**
@@ -71,9 +69,9 @@ public:
         ForwardedChannels = QProcess::ForwardedChannels,
             /**< Both standard output and standard error are forwarded
                  to the parent process' respective channel */
-        OnlyStdoutChannel = QProcess::ForwardedErrorChannel,
+        OnlyStdoutChannel = QProcess::ForwardedChannels,
             /**< Only standard output is handled; standard error is forwarded */
-        OnlyStderrChannel = QProcess::ForwardedOutputChannel
+        OnlyStderrChannel = QProcess::ForwardedChannels
             /**< Only standard error is handled; standard output is forwarded */
     };
 
@@ -314,6 +312,18 @@ public:
      */
     static int startDetached(const QStringList &argv);
 
+    /**
+     * Obtain the process' ID as known to the system.
+     *
+     * Unlike with QProcess::pid(), this is a real PID also on Windows.
+     *
+     * This function can be called only while the process is running.
+     * It cannot be applied to detached processes.
+     *
+     * @return the process ID
+     */
+    int pid() const;
+
 protected:
     /**
      * @internal
@@ -323,7 +333,7 @@ protected:
     /**
      * @internal
      */
-    std::unique_ptr<KProcessPrivate> const d_ptr;
+    KProcessPrivate * const d_ptr;
 
 private:
     // hide those
@@ -344,6 +354,9 @@ protected:
         q_ptr(qq)
     {
     }
+    virtual ~KProcessPrivate()
+    {
+    }
 
     QString prog;
     QStringList args;
diff --git a/lib/kpty.cpp b/lib/kpty.cpp
index 544749f..280bc70 100644
--- a/lib/kpty.cpp
+++ b/lib/kpty.cpp
@@ -205,6 +205,7 @@ KPty::KPty(KPtyPrivate *d) :
 KPty::~KPty()
 {
     close();
+    delete d_ptr;
 }
 
 bool KPty::open()
@@ -337,7 +338,7 @@ gotpty:
         qWarning()
         << "chownpty failed for device " << ptyName << "::" << d->ttyName
         << "\nThis means the communication can be eavesdropped."
-        << Qt::endl;
+        << endl;
     }
 
 #if defined (HAVE__GETPTY) || defined (HAVE_GRANTPT)
diff --git a/lib/kpty.h b/lib/kpty.h
index 648461c..36510ec 100644
--- a/lib/kpty.h
+++ b/lib/kpty.h
@@ -25,8 +25,6 @@
 
 #include <QObject>
 
-#include <memory>
-
 class KPtyPrivate;
 struct termios;
 
@@ -189,8 +187,7 @@ protected:
     /**
      * @internal
      */
-    std::unique_ptr<KPtyPrivate> const d_ptr;
+    KPtyPrivate * const d_ptr;
 };
 
 #endif
-
diff --git a/lib/kptyprocess.cpp b/lib/kptyprocess.cpp
index e73ef34..91492fa 100644
--- a/lib/kptyprocess.cpp
+++ b/lib/kptyprocess.cpp
@@ -48,7 +48,7 @@ KPtyProcess::KPtyProcess(int ptyMasterFd, QObject *parent) :
 {
     Q_D(KPtyProcess);
 
-    d->pty = std::make_unique<KPtyDevice>(this);
+    d->pty = new KPtyDevice(this);
 
     if (ptyMasterFd == -1) {
         d->pty->open();
@@ -56,11 +56,14 @@ KPtyProcess::KPtyProcess(int ptyMasterFd, QObject *parent) :
         d->pty->open(ptyMasterFd);
     }
 
-    connect(this, &QProcess::stateChanged, this, [this](QProcess::ProcessState state) {
-        if (state == QProcess::NotRunning && d_ptr->addUtmp) {
-            d_ptr->pty->logout();
-        }
-    });
+    connect(this, SIGNAL(stateChanged(QProcess::ProcessState)), this, SLOT(onStateChanged(QProcess::ProcessState)));
+}
+
+void KPtyProcess::onStateChanged(QProcess::ProcessState state)
+{
+    if (state == QProcess::NotRunning && d_ptr->addUtmp) {
+        d_ptr->pty->logout();
+    }
 }
 
 KPtyProcess::~KPtyProcess()
@@ -72,14 +75,14 @@ KPtyProcess::~KPtyProcess()
         if (d->addUtmp)
         {
             d->pty->logout();
-            disconnect(this, &QProcess::stateChanged, this, nullptr);
+            disconnect(this, SIGNAL(stateChanged(QProcess::ProcessState)), this, SLOT(onStateChanged(QProcess::ProcessState)));
         }
     }
     waitForFinished(300); // give it some time to finish
     if (state() != QProcess::NotRunning)
     {
         qWarning() << Q_FUNC_INFO << "the terminal process is still running, trying to stop it by SIGHUP";
-        ::kill(static_cast<pid_t>(processId()), SIGHUP);
+        ::kill(pid(), SIGHUP);
         waitForFinished(300);
         if (state() != QProcess::NotRunning)
             qCritical() << Q_FUNC_INFO << "process didn't stop upon SIGHUP and will be SIGKILL-ed";
@@ -118,7 +121,7 @@ KPtyDevice *KPtyProcess::pty() const
 {
     Q_D(const KPtyProcess);
 
-    return d->pty.get();
+    return d->pty;
 }
 
 void KPtyProcess::setupChildProcess()
diff --git a/lib/kptyprocess.h b/lib/kptyprocess.h
index 4d90823..af08ec3 100644
--- a/lib/kptyprocess.h
+++ b/lib/kptyprocess.h
@@ -34,7 +34,6 @@
 #include "kptydevice.h"
 
 #include <csignal>
-#include <memory>
 
 class KPtyDevice;
 
@@ -103,7 +102,7 @@ public:
     bool isRunning() const
     {
         bool rval;
-        (processId() > 0) ? rval= true : rval= false;
+        (pid() > 0) ? rval= true : rval= false;
         return rval;
 
     }
@@ -147,8 +146,11 @@ protected:
      */
     void setupChildProcess() override;
 
+protected slots:
+    void onStateChanged(QProcess::ProcessState state);
+
 private:
-    std::unique_ptr<KPtyProcessPrivate> const d_ptr;
+    KPtyProcessPrivate * const d_ptr;
 };
 
 
@@ -162,7 +164,7 @@ public:
     {
     }
 
-    std::unique_ptr<KPtyDevice> pty;
+    KPtyDevice *pty;
     KPtyProcess::PtyChannels ptyChannels = KPtyProcess::NoChannels;
     bool addUtmp = false;
 };
diff --git a/lib/qtermwidget.cpp b/lib/qtermwidget.cpp
index 07a0303..1baed58 100644
--- a/lib/qtermwidget.cpp
+++ b/lib/qtermwidget.cpp
@@ -83,9 +83,7 @@ Session *TermWidgetImpl::createSession(QWidget* parent)
      */
     //session->setProgram("/bin/bash");
 
-    session->setProgram(QString::fromLocal8Bit(qgetenv("SHELL")));
-
-
+    session->setProgram(QString::fromLocal8Bit(qgetenv("SHELL").constData()));
 
     QStringList args = QStringList(QString());
     session->setArguments(args);
@@ -168,7 +166,7 @@ void QTermWidget::search(bool forwards, bool next)
     //qDebug() << "current cursor position: " << m_impl->m_terminalDisplay->screenWindow()->cursorPosition();
 
     QRegExp regExp(m_searchBar->searchText());
-    regExp.setPatternSyntax(m_searchBar->useRegularExpression() ? QRegExp::RegExp : QRegExp::FixedString);
+    regExp.setPatternSyntax(m_searchBar->useRegExp() ? QRegExp::RegExp : QRegExp::FixedString);
     regExp.setCaseSensitivity(m_searchBar->matchCase() ? Qt::CaseSensitive : Qt::CaseInsensitive);
 
     HistorySearch *historySearch =
@@ -272,7 +270,7 @@ void QTermWidget::init(int startnow)
     // translations
     // First check $XDG_DATA_DIRS. This follows the implementation in libqtxdg
     QString d = QFile::decodeName(qgetenv("XDG_DATA_DIRS"));
-    QStringList dirs = d.split(QLatin1Char(':'), Qt::SkipEmptyParts);
+    QStringList dirs = d.split(QLatin1Char(':'), QString::SkipEmptyParts);
     if (dirs.isEmpty()) {
         dirs.append(QString::fromLatin1("/usr/local/share"));
         dirs.append(QString::fromLatin1("/usr/share"));
@@ -281,7 +279,7 @@ void QTermWidget::init(int startnow)
 
     m_translator = new QTranslator(this);
 
-    for (const QString& dir : qAsConst(dirs)) {
+    foreach (const QString& dir, dirs) {
         //qDebug() << "Trying to load translation file from dir" << dir;
         if (m_translator->load(QLocale::system(), QLatin1String("qtermwidget"), QLatin1String(QLatin1String("_")), dir)) {
             qApp->installTranslator(m_translator);
@@ -298,12 +296,12 @@ void QTermWidget::init(int startnow)
 
     connect(m_impl->m_session, SIGNAL(activity()), this, SIGNAL(activity()));
     connect(m_impl->m_session, SIGNAL(silence()), this, SIGNAL(silence()));
-    connect(m_impl->m_session, &Session::profileChangeCommandReceived, this, &QTermWidget::profileChanged);
-    connect(m_impl->m_session, &Session::receivedData, this, &QTermWidget::receivedData);
+    connect(m_impl->m_session, SIGNAL(profileChangeCommandReceived(QString)), this, SLOT(profileChanged(QString)));
+    connect(m_impl->m_session, SIGNAL(receivedData(QString)), this, SLOT(receivedData(QString)));
 
     // That's OK, FilterChain's dtor takes care of UrlFilter.
     UrlFilter *urlFilter = new UrlFilter();
-    connect(urlFilter, &UrlFilter::activated, this, &QTermWidget::urlActivated);
+    connect(urlFilter, SIGNAL(activated(QUrl,bool)), this, SLOT(urlActivated(QUrl,bool)));
     m_impl->m_terminalDisplay->filterChain()->addFilter(urlFilter);
 
     m_searchBar = new SearchBar(this);
@@ -329,8 +327,8 @@ void QTermWidget::init(int startnow)
             this, SIGNAL(termGetFocus()));
     connect(m_impl->m_terminalDisplay, SIGNAL(termLostFocus()),
             this, SIGNAL(termLostFocus()));
-    connect(m_impl->m_terminalDisplay, &TerminalDisplay::keyPressedSignal, this,
-            [this] (QKeyEvent* e, bool) { Q_EMIT termKeyPressed(e); });
+    connect(m_impl->m_terminalDisplay, SIGNAL(keyPressedSignal(QKeyEvent*,bool)),
+            this, SLOT(termKeyPressed(QKeyEvent*,bool)));
 //    m_impl->m_terminalDisplay->setSize(80, 40);
 
     QFont font = QApplication::font();
@@ -347,18 +345,17 @@ void QTermWidget::init(int startnow)
 
     connect(m_impl->m_session, SIGNAL(resizeRequest(QSize)), this, SLOT(setSize(QSize)));
     connect(m_impl->m_session, SIGNAL(finished()), this, SLOT(sessionFinished()));
-    connect(m_impl->m_session, &Session::titleChanged, this, &QTermWidget::titleChanged);
-    connect(m_impl->m_session, &Session::cursorChanged, this, &QTermWidget::cursorChanged);
+    connect(m_impl->m_session, SIGNAL(titleChanged()), this, SLOT(titleChanged()));
+    connect(m_impl->m_session, SIGNAL(cursorChanged(Konsole::Emulation::KeyboardCursorShape,bool)),
+            this, SLOT(cursorChanged(Konsole::Emulation::KeyboardCursorShape,bool)));
 }
 
-
 QTermWidget::~QTermWidget()
 {
     delete m_impl;
     emit destroyed();
 }
 
-
 void QTermWidget::setTerminalFont(const QFont &font)
 {
     m_impl->m_terminalDisplay->setVTFont(font);
diff --git a/lib/qtermwidget.h b/lib/qtermwidget.h
index d7532fc..ba1a78c 100644
--- a/lib/qtermwidget.h
+++ b/lib/qtermwidget.h
@@ -35,7 +35,6 @@ class QUrl;
 
 class QTERMWIDGET_EXPORT QTermWidget : public QWidget, public QTermWidgetInterface {
     Q_OBJECT
-    Q_PLUGIN_METADATA(IID "lxqt.qtermwidget" FILE "qtermwidget.json")
     Q_INTERFACES(QTermWidgetInterface)
 
 public:
diff --git a/lib/tools.cpp b/lib/tools.cpp
index 4291fae..8bc3909 100644
--- a/lib/tools.cpp
+++ b/lib/tools.cpp
@@ -5,8 +5,6 @@
 #include <QtDebug>
 
 
-Q_LOGGING_CATEGORY(qtermwidgetLogger, "qtermwidget", QtWarningMsg)
-
 /*! Helper function to get possible location of layout files.
 By default the KB_LAYOUT_DIR is used (linux/BSD/macports).
 But in some cases (apple bundle) there can be more locations).
@@ -89,7 +87,7 @@ const QStringList get_color_schemes_dirs()
     }
 #endif
 
-    for (const QString& custom_dir : qAsConst(custom_color_schemes_dirs))
+    for (const QString& custom_dir : const_cast<const QStringList&>(custom_color_schemes_dirs))
     {
         d.setPath(custom_dir);
         if (d.exists())
diff --git a/lib/tools.h b/lib/tools.h
index 239689b..455037e 100644
--- a/lib/tools.h
+++ b/lib/tools.h
@@ -3,12 +3,9 @@
 
 #include <QString>
 #include <QStringList>
-#include <QLoggingCategory>
 
 QString get_kb_layout_dir();
 void add_custom_color_scheme_dir(const QString& custom_dir);
 const QStringList get_color_schemes_dirs();
 
-Q_DECLARE_LOGGING_CATEGORY(qtermwidgetLogger)
-
 #endif
diff --git a/pyqt/sip/qtermwidget.sip b/pyqt/sip/qtermwidget.sip
index 21a10f8..d23a574 100644
--- a/pyqt/sip/qtermwidget.sip
+++ b/pyqt/sip/qtermwidget.sip
@@ -22,7 +22,7 @@ public:
         ScrollBarRight=2
     };
 
-    enum class KeyboardCursorShape
+    enum KeyboardCursorShape
     {
         BlockCursor=0,
         UnderlineCursor=1,
