Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qlocalsocket.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
4#ifndef QLOCALSOCKET_H
5#define QLOCALSOCKET_H
6
7#include <QtNetwork/qtnetworkglobal.h>
8#include <QtCore/qiodevice.h>
9#include <QtNetwork/qabstractsocket.h>
10
11#ifndef QT_NO_DEBUG_STREAM
12#include <QtCore/qdebug.h>
13#endif
14
15QT_REQUIRE_CONFIG(localserver);
16
18
20
21class Q_NETWORK_EXPORT QLocalSocket : public QIODevice
22{
24 Q_DECLARE_PRIVATE(QLocalSocket)
25 Q_PROPERTY(SocketOptions socketOptions READ socketOptions WRITE setSocketOptions
26 BINDABLE bindableSocketOptions)
27
28public:
43
51
53 NoOptions = 0x00,
54 AbstractNamespaceOption = 0x01
55 };
56 Q_DECLARE_FLAGS(SocketOptions, SocketOption)
57 Q_FLAG(SocketOptions)
58
59 QLocalSocket(QObject *parent = nullptr);
61
62 void connectToServer(OpenMode openMode = ReadWrite);
63 void connectToServer(const QString &name, OpenMode openMode = ReadWrite);
65
66 void setServerName(const QString &name);
67 QString serverName() const;
68 QString fullServerName() const;
69
70 void abort();
71 virtual bool isSequential() const override;
72 virtual qint64 bytesAvailable() const override;
73 virtual qint64 bytesToWrite() const override;
74 virtual bool canReadLine() const override;
75 virtual bool open(OpenMode openMode = ReadWrite) override;
76 virtual void close() override;
77 LocalSocketError error() const;
78 bool flush();
79 bool isValid() const;
80 qint64 readBufferSize() const;
81 void setReadBufferSize(qint64 size);
82
83 bool setSocketDescriptor(qintptr socketDescriptor,
84 LocalSocketState socketState = ConnectedState,
85 OpenMode openMode = ReadWrite);
86 qintptr socketDescriptor() const;
87
88 void setSocketOptions(SocketOptions option);
89 SocketOptions socketOptions() const;
90 QBindable<SocketOptions> bindableSocketOptions();
91
92 LocalSocketState state() const;
93 bool waitForBytesWritten(int msecs = 30000) override;
94 bool waitForConnected(int msecs = 30000);
95 bool waitForDisconnected(int msecs = 30000);
96 bool waitForReadyRead(int msecs = 30000) override;
97
99 void connected();
103
104protected:
105 virtual qint64 readData(char*, qint64) override;
106 qint64 readLineData(char *data, qint64 maxSize) override;
107 qint64 skipData(qint64 maxSize) override;
108 virtual qint64 writeData(const char*, qint64) override;
109
110private:
111 Q_DISABLE_COPY(QLocalSocket)
112#if defined(QT_LOCALSOCKET_TCP)
113 Q_PRIVATE_SLOT(d_func(), void _q_stateChanged(QAbstractSocket::SocketState))
114 Q_PRIVATE_SLOT(d_func(), void _q_errorOccurred(QAbstractSocket::SocketError))
115#elif defined(Q_OS_WIN)
116 Q_PRIVATE_SLOT(d_func(), void _q_pipeClosed())
117 Q_PRIVATE_SLOT(d_func(), void _q_winError(ulong, const QString &))
118#else
119 Q_PRIVATE_SLOT(d_func(), void _q_stateChanged(QAbstractSocket::SocketState))
120 Q_PRIVATE_SLOT(d_func(), void _q_errorOccurred(QAbstractSocket::SocketError))
121 Q_PRIVATE_SLOT(d_func(), void _q_connectToSocket())
122 Q_PRIVATE_SLOT(d_func(), void _q_abortConnectionAttempt())
123#endif
124};
125
126#ifndef QT_NO_DEBUG_STREAM
129#endif
130
131Q_DECLARE_OPERATORS_FOR_FLAGS(QLocalSocket::SocketOptions)
132
134
135#endif // QLOCALSOCKET_H
SocketState
This enum describes the different states in which a socket can be.
SocketError
This enum describes the socket errors that can occur.
\inmodule QtCore
\inmodule QtCore \reentrant
Definition qiodevice.h:34
The QLocalSocket class provides a local socket.
void connected()
This signal is emitted after connectToServer() has been called and a connection has been successfully...
void disconnected()
This signal is emitted when the socket has been disconnected.
LocalSocketState
This enum describes the different states in which a socket can be.
void stateChanged(QLocalSocket::LocalSocketState socketState)
This signal is emitted whenever QLocalSocket's state changes.
LocalSocketError
The LocalServerError enumeration represents the errors that can occur.
void errorOccurred(QLocalSocket::LocalSocketError socketError)
\inmodule QtCore
Definition qobject.h:103
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
else opt state
[0]
Combined button and popup list for selecting options.
DBusConnection const char DBusError * error
#define Q_DECLARE_FLAGS(Flags, Enum)
Definition qflags.h:174
#define Q_DECLARE_OPERATORS_FOR_FLAGS(Flags)
Definition qflags.h:194
Q_NETWORK_EXPORT QDebug operator<<(QDebug, QLocalSocket::LocalSocketError)
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLuint name
GLuint GLenum option
#define QT_REQUIRE_CONFIG(feature)
#define Q_PROPERTY(...)
#define Q_OBJECT
#define Q_FLAG(x)
#define Q_PRIVATE_SLOT(d, signature)
#define Q_SIGNALS
unsigned long ulong
Definition qtypes.h:35
long long qint64
Definition qtypes.h:60
ptrdiff_t qintptr
Definition qtypes.h:166
file open(QIODevice::ReadOnly)
device waitForReadyRead(deadline)
void writeData(const QByteArray &data)
QByteArray readData()
socket disconnectFromServer()
[0]
socket connectToServer("market")
[0]