Qt 6.x
The Qt SDK
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:
30 {
39 UnsupportedSocketOperationError = QAbstractSocket::UnsupportedSocketOperationError,
41 OperationError = QAbstractSocket::OperationError
42 };
43
45 {
50 };
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
Definition qproperty.h:809
\inmodule QtCore
\inmodule QtCore \reentrant
Definition qiodevice.h:34
virtual bool open(QIODeviceBase::OpenMode mode)
Opens the device and sets its OpenMode to mode.
virtual bool isSequential() const
Returns true if this device is sequential; otherwise returns false.
virtual bool waitForBytesWritten(int msecs)
For buffered devices, this function waits until a payload of buffered written data has been written t...
virtual bool waitForReadyRead(int msecs)
Blocks until new data is available for reading and the readyRead() signal has been emitted,...
virtual qint64 bytesAvailable() const
Returns the number of bytes that are available for reading.
virtual qint64 skipData(qint64 maxSize)
virtual qint64 readLineData(char *data, qint64 maxlen)
Reads up to maxSize characters into data and returns the number of characters read.
virtual qint64 writeData(const char *data, qint64 len)=0
Writes up to maxSize bytes from data to the device.
virtual qint64 bytesToWrite() const
For buffered devices, this function returns the number of bytes waiting to be written.
virtual void close()
First emits aboutToClose(), then closes the device and sets its OpenMode to NotOpen.
virtual bool canReadLine() const
Returns true if a complete line of data can be read from the device; otherwise returns false.
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:90
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
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:30
long long qint64
Definition qtypes.h:55
ptrdiff_t qintptr
Definition qtypes.h:71
QByteArray readData()
socket disconnectFromServer()
[0]
socket connectToServer("market")
[0]
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent