QLocalSocket Class
The QLocalSocket class provides a local socket. More...
Header: | #include <QLocalSocket> |
qmake: | QT += network |
Since: | Qt 4.4 |
Inherits: | QIODevice |
This class was introduced in Qt 4.4.
Public Types
enum | LocalSocketError { ConnectionRefusedError, PeerClosedError, ServerNotFoundError, SocketAccessError, ..., UnknownSocketError } |
enum | LocalSocketState { UnconnectedState, ConnectingState, ConnectedState, ClosingState } |
Public Functions
QLocalSocket(QObject *parent = nullptr) | |
virtual | ~QLocalSocket() |
void | connectToServer(const QString &name, QIODevice::OpenMode openMode = ReadWrite) |
QString | fullServerName() const |
QString | serverName() const |
void | setServerName(const QString &name) |
QLocalSocket::LocalSocketState | state() const |
Reimplemented Public Functions
virtual bool | isSequential() const override |
Related Non-Members
typedef | QObjectList |
Macros
QT_NO_NARROWING_CONVERSIONS_IN_CONNECT | |
Q_CLASSINFO(Name, Value) | |
Q_DISABLE_COPY(Class) | |
Q_DISABLE_COPY_MOVE(Class) | |
Q_DISABLE_MOVE(Class) | |
Q_EMIT | |
Q_ENUM(...) | |
Q_ENUM_NS(...) | |
Q_FLAG(...) | |
Q_FLAG_NS(...) | |
Q_GADGET | |
Q_INTERFACES(...) | |
Q_INVOKABLE | |
Q_NAMESPACE | |
Q_OBJECT | |
Q_PROPERTY(...) | |
Q_REVISION | |
Q_SET_OBJECT_NAME(Object) | |
Q_SIGNAL | |
Q_SIGNALS | |
Q_SLOT | |
Q_SLOTS |
Additional Inherited Members
- 1 property inherited from QObject
- 1 public slot inherited from QObject
- 1 signal inherited from QObject
- 5 static public members inherited from QObject
- 3 protected functions inherited from QIODevice
- 8 protected functions inherited from QObject
Detailed Description
On Windows this is a named pipe and on Unix this is a local domain socket.
If an error occurs, socketError() returns the type of error, and errorString() can be called to get a human readable description of what happened.
Although QLocalSocket is designed for use with an event loop, it's possible to use it without one. In that case, you must use waitForConnected(), waitForReadyRead(), waitForBytesWritten(), and waitForDisconnected() which blocks until the operation is complete or the timeout expires.
See also QLocalServer.
Member Type Documentation
enum QLocalSocket::LocalSocketError
The LocalServerError enumeration represents the errors that can occur. The most recent error can be retrieved through a call to QLocalSocket::error().
Constant | Value | Description |
---|---|---|
QLocalSocket::ConnectionRefusedError | QAbstractSocket::ConnectionRefusedError | The connection was refused by the peer (or timed out). |
QLocalSocket::PeerClosedError | QAbstractSocket::RemoteHostClosedError | The remote socket closed the connection. Note that the client socket (i.e., this socket) will be closed after the remote close notification has been sent. |
QLocalSocket::ServerNotFoundError | QAbstractSocket::HostNotFoundError | The local socket name was not found. |
QLocalSocket::SocketAccessError | QAbstractSocket::SocketAccessError | The socket operation failed because the application lacked the required privileges. |
QLocalSocket::SocketResourceError | QAbstractSocket::SocketResourceError | The local system ran out of resources (e.g., too many sockets). |
QLocalSocket::SocketTimeoutError | QAbstractSocket::SocketTimeoutError | The socket operation timed out. |
QLocalSocket::DatagramTooLargeError | QAbstractSocket::DatagramTooLargeError | The datagram was larger than the operating system's limit (which can be as low as 8192 bytes). |
QLocalSocket::ConnectionError | QAbstractSocket::NetworkError | An error occurred with the connection. |
QLocalSocket::UnsupportedSocketOperationError | QAbstractSocket::UnsupportedSocketOperationError | The requested socket operation is not supported by the local operating system. |
QLocalSocket::OperationError | QAbstractSocket::OperationError | An operation was attempted while the socket was in a state that did not permit it. |
QLocalSocket::UnknownSocketError | QAbstractSocket::UnknownSocketError | An unidentified error occurred. |
enum QLocalSocket::LocalSocketState
This enum describes the different states in which a socket can be.
Constant | Value | Description |
---|---|---|
QLocalSocket::UnconnectedState | QAbstractSocket::UnconnectedState | The socket is not connected. |
QLocalSocket::ConnectingState | QAbstractSocket::ConnectingState | The socket has started establishing a connection. |
QLocalSocket::ConnectedState | QAbstractSocket::ConnectedState | A connection is established. |
QLocalSocket::ClosingState | QAbstractSocket::ClosingState | The socket is about to close (data may still be waiting to be written). |
See also QLocalSocket::state().
Member Function Documentation
QLocalSocket::QLocalSocket(QObject *parent = nullptr)
Creates a new local socket. The parent argument is passed to QObject's constructor.
[virtual]
QLocalSocket::~QLocalSocket()
Destroys the socket, closing the connection if necessary.
void QLocalSocket::connectToServer(const QString &name, QIODevice::OpenMode openMode = ReadWrite)
This is an overloaded function.
Set the server name and attempts to make a connection to it.
The socket is opened in the given openMode and first enters ConnectingState. If a connection is established, QLocalSocket enters ConnectedState and emits connected().
After calling this function, the socket can emit error() to signal that an error occurred.
See also state(), serverName(), and waitForConnected().
QString QLocalSocket::fullServerName() const
Returns the server path that the socket is connected to.
Note: The return value of this function is platform specific.
See also connectToServer() and serverName().
[override virtual]
bool QLocalSocket::isSequential() const
Reimplements: QIODevice::isSequential() const.
QString QLocalSocket::serverName() const
Returns the name of the peer as specified by setServerName(), or an empty QString if setServerName() has not been called or connectToServer() failed.
See also setServerName(), connectToServer(), and fullServerName().
void QLocalSocket::setServerName(const QString &name)
Set the name of the peer to connect to. On Windows name is the name of a named pipe; on Unix name is the name of a local domain socket.
This function must be called when the socket is not connected.
This function was introduced in Qt 5.1.
See also serverName().
QLocalSocket::LocalSocketState QLocalSocket::state() const
Returns the state of the socket.
See also error().