Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qsocketnotifier.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#ifndef QSOCKETNOTIFIER_H
6#define QSOCKETNOTIFIER_H
7
8#include <QtCore/qobject.h>
9
11
14class Q_CORE_EXPORT QSocketNotifier : public QObject
15{
16 Q_OBJECT
17 Q_DECLARE_PRIVATE(QSocketNotifier)
18
19public:
20 enum Type { Read, Write, Exception };
21
22 explicit QSocketNotifier(Type, QObject *parent = nullptr);
23 QSocketNotifier(qintptr socket, Type, QObject *parent = nullptr);
24 ~QSocketNotifier();
25
26 void setSocket(qintptr socket);
27 qintptr socket() const;
28 Type type() const;
29
30 bool isValid() const;
31 bool isEnabled() const;
32
33public Q_SLOTS:
34 void setEnabled(bool);
35
36Q_SIGNALS:
37#if defined(Q_MOC_RUN)
38 // Add default arguments during Q_MOC_RUN which makes moc generate "signals" which takes less
39 // parameters, but we won't actually allow emitting without all 3. This lets users use the
40 // string-based connect without specifying QSocketNotifier::Type as one of the parameters.
41 void activated(QSocketDescriptor socket, QSocketNotifier::Type activationEvent = Read,
42 QPrivateSignal = {});
43#else
44 void activated(QSocketDescriptor socket, QSocketNotifier::Type activationEvent, QPrivateSignal);
45#endif
46
47 // ### Qt7: consider removing it.
48 // The old signal is compiled internally, but hidden outside of this class.
49 // This means the PMF-based connect(..) will automatically, on recompile, pick up the new
50 // version while the old-style connect(..) can query the metaobject system for this version.
51#if defined(Q_MOC_RUN) || defined(BUILDING_QSOCKETNOTIFIER) || defined(Q_QDOC)
52 QT_MOC_COMPAT void activated(int socket, QPrivateSignal);
53#endif
54
55protected:
56 bool event(QEvent *) override;
57
58private:
59 Q_DISABLE_COPY(QSocketNotifier)
60};
61
63{
64public:
65#if defined(Q_OS_WIN) || defined(Q_QDOC)
66 using DescriptorType = Qt::HANDLE;
67#define Q_DECL_CONSTEXPR_NOT_WIN
68#else
69 using DescriptorType = int;
70#define Q_DECL_CONSTEXPR_NOT_WIN Q_DECL_CONSTEXPR
71#endif
72
77
78#if defined(Q_OS_WIN) || defined(Q_QDOC)
80 Q_IMPLICIT operator qintptr() const noexcept { return qintptr(sockfd); }
81 Q_DECL_CONSTEXPR Qt::HANDLE winHandle() const noexcept { return sockfd; }
82#endif
83 Q_DECL_CONSTEXPR operator DescriptorType() const noexcept { return sockfd; }
84
85 Q_DECL_CONSTEXPR_NOT_WIN bool isValid() const noexcept { return *this != QSocketDescriptor(); }
86
87private:
89 const QSocketDescriptor &rhs) noexcept
90 {
91 return lhs.sockfd == rhs.sockfd;
92 }
93#if defined(Q_OS_WIN) || defined(Q_QDOC)
95#else
97#endif
98
99#undef Q_DECL_CONSTEXPR_NOT_WIN
100
102};
103
104QT_END_NAMESPACE
105
106QT_DECL_METATYPE_EXTERN_TAGGED(QSocketNotifier::Type, QSocketNotifier_Type, Q_CORE_EXPORT)
107QT_DECL_METATYPE_EXTERN(QSocketDescriptor, Q_CORE_EXPORT)
108
109#endif // QSOCKETNOTIFIER_H
\inmodule QtCore
\inmodule QtCore
Combined button and popup list for selecting options.
QT_REQUIRE_CONFIG(animation)
QT_REQUIRE_CONFIG(filesystemwatcher)
Hash::const_iterator find_last_in_equal_range(const Hash &c, const Key &key)
#define Q_DECL_CONSTEXPR_NOT_WIN