summaryrefslogtreecommitdiff
path: root/map65/QtErrorCompat.h
diff options
context:
space:
mode:
authorhibby <d@vehibberd.com>2026-10-06 21:24:40 +0100
committerhibby <d@vehibberd.com>2026-10-06 21:24:40 +0100
commitc25cbdf6fb6d946175f4335fab77bfea601b56db (patch)
tree6f7a94b7b81f999e434f61b73d47e337dfd26bf2 /map65/QtErrorCompat.h
parent71f5689252c9f13e70e1c24856904475b2307809 (diff)
parent0685fcada9f95fe90f70b387cd7d757da8209624 (diff)
Merge tag 'debian/3.2.0_rc1+dfsg-2' into debian/trixie-backportsdebian/trixie-backports
tagging wsjtx 3.2.0~rc1+dfsg-2
Diffstat (limited to 'map65/QtErrorCompat.h')
-rw-r--r--map65/QtErrorCompat.h106
1 files changed, 106 insertions, 0 deletions
diff --git a/map65/QtErrorCompat.h b/map65/QtErrorCompat.h
new file mode 100644
index 00000000..01a8c012
--- /dev/null
+++ b/map65/QtErrorCompat.h
@@ -0,0 +1,106 @@
+#ifndef QT_ERROR_COMPAT_H
+#define QT_ERROR_COMPAT_H
+
+#include <QObject>
+#include <QProcess>
+#include <QAbstractSocket>
+
+// ---------------------------------------------------------------------------
+// QtErrorCompat
+//
+// Provides a unified way to connect to error signals across all Qt versions
+// from 5.12.12 through 6.x, without using QT_VERSION checks.
+//
+// It connects BOTH the legacy "error(...)" signal and the newer
+// "errorOccurred(...)" signal, but guarantees that your slot is invoked
+// only once per error event.
+// ---------------------------------------------------------------------------
+
+class QtErrorCompat : public QObject
+{
+ Q_OBJECT
+
+public:
+ explicit QtErrorCompat(QObject *parent = nullptr)
+ : QObject(parent)
+ {}
+
+ // -----------------------------------------------------------------------
+ // Connect QProcess error signals
+ // -----------------------------------------------------------------------
+ template<typename Receiver>
+ void connectErrors(QProcess *proc,
+ Receiver *receiver,
+ void (Receiver::*slot)(QProcess::ProcessError))
+ {
+ // Newer Qt (5.15+)
+ QObject::connect(proc,
+ SIGNAL(errorOccurred(QProcess::ProcessError)),
+ this,
+ SLOT(handleProcessError(QProcess::ProcessError)));
+
+ // Older Qt (5.12.12)
+ QObject::connect(proc,
+ QOverload<QProcess::ProcessError>::of(&QProcess::error),
+ this,
+ &QtErrorCompat::handleProcessError);
+
+ // Forward to user slot
+ QObject::connect(this,
+ &QtErrorCompat::processError,
+ receiver,
+ slot);
+ }
+
+ // -----------------------------------------------------------------------
+ // Connect QAbstractSocket error signals (QTcpSocket, QUdpSocket, etc.)
+ // -----------------------------------------------------------------------
+ template<typename Receiver>
+ void connectErrors(QAbstractSocket *sock,
+ Receiver *receiver,
+ void (Receiver::*slot)(QAbstractSocket::SocketError))
+ {
+ // Newer Qt (5.15+)
+ QObject::connect(sock,
+ SIGNAL(errorOccurred(QAbstractSocket::SocketError)),
+ this,
+ SLOT(handleSocketError(QAbstractSocket::SocketError)));
+
+ // Older Qt (5.12.12)
+ QObject::connect(sock,
+ QOverload<QAbstractSocket::SocketError>::of(&QAbstractSocket::error),
+ this,
+ &QtErrorCompat::handleSocketError);
+
+ // Forward to user slot
+ QObject::connect(this,
+ &QtErrorCompat::socketError,
+ receiver,
+ slot);
+ }
+
+signals:
+ void processError(QProcess::ProcessError);
+ void socketError(QAbstractSocket::SocketError);
+
+private slots:
+ void handleProcessError(QProcess::ProcessError e)
+ {
+ static bool guard = false;
+ if (guard) return;
+ guard = true;
+ emit processError(e);
+ guard = false;
+ }
+
+ void handleSocketError(QAbstractSocket::SocketError e)
+ {
+ static bool guard = false;
+ if (guard) return;
+ guard = true;
+ emit socketError(e);
+ guard = false;
+ }
+};
+
+#endif // QT_ERROR_COMPAT_H