diff options
author | Alex Trotsenko <alex1973tr@gmail.com> | 2020-12-09 20:54:00 +0200 |
---|---|---|
committer | Alex Trotsenko <alex1973tr@gmail.com> | 2020-12-11 18:08:31 +0200 |
commit | 6dac45b24647aba4f5274e3908fc7bb661bcbef5 (patch) | |
tree | 3ab123dd42223e9883d2954467e57d4b6d2607b5 /src/corelib/kernel/qsocketnotifier.h | |
parent | 7715b186c79a968950fd1c8e0993641f2f58b3be (diff) |
QSocketNotifier: extend API to provide more flexible startup
Technically, having a single constructor limits the use-cases for this
class. We should take into account that:
- an opened socket descriptor must be available at the moment of
construction;
- the constructor unconditionally enables the notifier (the possible
solution
notifier = new QSocketNotifier(...);
notifier->setEnabled(false);
is suboptimal due to heavy operations inside the event dispatcher);
- for these reasons, QSocketNotifier most often cannot be a member of
another class (we have an extra allocation and indirect access).
This patch addresses this shortcoming by making it possible to set the
socket descriptor at a later point:
[ChangeLog][QtCore][QSocketNotifier] Added setSocket() and an additional
constructor which requires no socket.
Change-Id: I2eb2edf33ddafe99e528aac7d3774ade40795e7a
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
Diffstat (limited to 'src/corelib/kernel/qsocketnotifier.h')
-rw-r--r-- | src/corelib/kernel/qsocketnotifier.h | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/src/corelib/kernel/qsocketnotifier.h b/src/corelib/kernel/qsocketnotifier.h index b8a5cc542a..fdf11961c3 100644 --- a/src/corelib/kernel/qsocketnotifier.h +++ b/src/corelib/kernel/qsocketnotifier.h @@ -54,12 +54,15 @@ class Q_CORE_EXPORT QSocketNotifier : public QObject public: enum Type { Read, Write, Exception }; + explicit QSocketNotifier(Type, QObject *parent = nullptr); QSocketNotifier(qintptr socket, Type, QObject *parent = nullptr); ~QSocketNotifier(); + void setSocket(qintptr socket, bool enable = false); qintptr socket() const; Type type() const; + bool isValid() const; bool isEnabled() const; public Q_SLOTS: |