![]() |
Qt 6.x
The Qt SDK
|
The QLocalSocket class provides a local socket. More...
#include <qlocalsocket.h>
Public Types | |
enum | LocalSocketError { ConnectionRefusedError = QAbstractSocket::ConnectionRefusedError , PeerClosedError = QAbstractSocket::RemoteHostClosedError , ServerNotFoundError = QAbstractSocket::HostNotFoundError , SocketAccessError = QAbstractSocket::SocketAccessError , SocketResourceError = QAbstractSocket::SocketResourceError , SocketTimeoutError = QAbstractSocket::SocketTimeoutError , DatagramTooLargeError = QAbstractSocket::DatagramTooLargeError , ConnectionError = QAbstractSocket::NetworkError , UnsupportedSocketOperationError = QAbstractSocket::UnsupportedSocketOperationError , UnknownSocketError = QAbstractSocket::UnknownSocketError , OperationError = QAbstractSocket::OperationError } |
The LocalServerError enumeration represents the errors that can occur. More... | |
enum | LocalSocketState { UnconnectedState = QAbstractSocket::UnconnectedState , ConnectingState = QAbstractSocket::ConnectingState , ConnectedState = QAbstractSocket::ConnectedState , ClosingState = QAbstractSocket::ClosingState } |
This enum describes the different states in which a socket can be. More... | |
enum | SocketOption { NoOptions = 0x00 , AbstractNamespaceOption = 0x01 } |
![]() | |
enum | OpenModeFlag { NotOpen = 0x0000 , ReadOnly = 0x0001 , WriteOnly = 0x0002 , ReadWrite = ReadOnly | WriteOnly , Append = 0x0004 , Truncate = 0x0008 , Text = 0x0010 , Unbuffered = 0x0020 , NewOnly = 0x0040 , ExistingOnly = 0x0080 } |
This enum is used with QIODevice::open() to describe the mode in which a device is opened. More... | |
Signals | |
void | connected () |
This signal is emitted after connectToServer() has been called and a connection has been successfully established. | |
void | disconnected () |
This signal is emitted when the socket has been disconnected. | |
void | errorOccurred (QLocalSocket::LocalSocketError socketError) |
void | stateChanged (QLocalSocket::LocalSocketState socketState) |
This signal is emitted whenever QLocalSocket's state changes. | |
![]() | |
void | readyRead () |
This signal is emitted once every time new data is available for reading from the device's current read channel. | |
void | channelReadyRead (int channel) |
void | bytesWritten (qint64 bytes) |
This signal is emitted every time a payload of data has been written to the device's current write channel. | |
void | channelBytesWritten (int channel, qint64 bytes) |
void | aboutToClose () |
This signal is emitted when the device is about to close. | |
void | readChannelFinished () |
![]() | |
void | destroyed (QObject *=nullptr) |
This signal is emitted immediately before the object obj is destroyed, after any instances of QPointer have been notified, and cannot be blocked. | |
void | objectNameChanged (const QString &objectName, QPrivateSignal) |
This signal is emitted after the object's name has been changed. | |
Public Member Functions | |
QLocalSocket (QObject *parent=nullptr) | |
Creates a new local socket. | |
~QLocalSocket () | |
Destroys the socket, closing the connection if necessary. | |
void | connectToServer (OpenMode openMode=ReadWrite) |
void | connectToServer (const QString &name, OpenMode openMode=ReadWrite) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Set the server name and attempts to make a connection to it. | |
void | disconnectFromServer () |
Attempts to close the socket. | |
void | setServerName (const QString &name) |
QString | 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. | |
QString | fullServerName () const |
Returns the server path that the socket is connected to. | |
void | abort () |
Aborts the current connection and resets the socket. | |
virtual bool | isSequential () const override |
\reimp | |
virtual qint64 | bytesAvailable () const override |
\reimp | |
virtual qint64 | bytesToWrite () const override |
\reimp | |
virtual bool | canReadLine () const override |
\reimp | |
virtual bool | open (OpenMode openMode=ReadWrite) override |
Equivalent to connectToServer(OpenMode mode). | |
virtual void | close () override |
Closes the I/O device for the socket and calls disconnectFromServer() to close the socket's connection. | |
LocalSocketError | error () const |
Returns the type of error that last occurred. | |
bool | flush () |
This function writes as much as possible from the internal write buffer to the socket, without blocking. | |
bool | isValid () const |
Returns true if the socket is valid and ready for use; otherwise returns false . | |
qint64 | readBufferSize () const |
Returns the size of the internal read buffer. | |
void | setReadBufferSize (qint64 size) |
Sets the size of QLocalSocket's internal read buffer to be size bytes. | |
bool | setSocketDescriptor (qintptr socketDescriptor, LocalSocketState socketState=ConnectedState, OpenMode openMode=ReadWrite) |
Initializes QLocalSocket with the native socket descriptor socketDescriptor. | |
qintptr | socketDescriptor () const |
Returns the native socket descriptor of the QLocalSocket object if this is available; otherwise returns -1. | |
void | setSocketOptions (SocketOptions option) |
SocketOptions | socketOptions () const |
QBindable< SocketOptions > | bindableSocketOptions () |
LocalSocketState | state () const |
Returns the state of the socket. | |
bool | waitForBytesWritten (int msecs=30000) override |
\reimp | |
bool | waitForConnected (int msecs=30000) |
Waits until the socket is connected, up to msecs milliseconds. | |
bool | waitForDisconnected (int msecs=30000) |
Waits until the socket has disconnected, up to msecs milliseconds. | |
bool | waitForReadyRead (int msecs=30000) override |
This function blocks until data is available for reading and the \l{QIODevice::}{readyRead()} signal has been emitted. | |
![]() | |
QIODevice () | |
Constructs a QIODevice object. | |
QIODevice (QObject *parent) | |
Constructs a QIODevice object with the given parent. | |
virtual | ~QIODevice () |
The destructor is virtual, and QIODevice is an abstract base class. | |
QIODeviceBase::OpenMode | openMode () const |
Returns the mode in which the device has been opened; i.e. | |
void | setTextModeEnabled (bool enabled) |
If enabled is true, this function sets the \l Text flag on the device; otherwise the \l Text flag is removed. | |
bool | isTextModeEnabled () const |
Returns true if the \l Text flag is enabled; otherwise returns false . | |
bool | isOpen () const |
Returns true if the device is open; otherwise returns false . | |
bool | isReadable () const |
Returns true if data can be read from the device; otherwise returns false. | |
bool | isWritable () const |
Returns true if data can be written to the device; otherwise returns false. | |
virtual bool | isSequential () const |
Returns true if this device is sequential; otherwise returns false. | |
int | readChannelCount () const |
int | writeChannelCount () const |
int | currentReadChannel () const |
void | setCurrentReadChannel (int channel) |
int | currentWriteChannel () const |
void | setCurrentWriteChannel (int channel) |
virtual bool | open (QIODeviceBase::OpenMode mode) |
Opens the device and sets its OpenMode to mode. | |
virtual void | close () |
First emits aboutToClose(), then closes the device and sets its OpenMode to NotOpen. | |
virtual qint64 | pos () const |
For random-access devices, this function returns the position that data is written to or read from. | |
virtual qint64 | size () const |
For open random-access devices, this function returns the size of the device. | |
virtual bool | seek (qint64 pos) |
For random-access devices, this function sets the current position to pos, returning true on success, or false if an error occurred. | |
virtual bool | atEnd () const |
Returns true if the current read and write position is at the end of the device (i.e. | |
virtual bool | reset () |
Seeks to the start of input for random-access devices. | |
virtual qint64 | bytesAvailable () const |
Returns the number of bytes that are available for reading. | |
virtual qint64 | bytesToWrite () const |
For buffered devices, this function returns the number of bytes waiting to be written. | |
qint64 | read (char *data, qint64 maxlen) |
Reads at most maxSize bytes from the device into data, and returns the number of bytes read. | |
QByteArray | read (qint64 maxlen) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Reads at most maxSize bytes from the device, and returns the data read as a QByteArray. | |
QByteArray | readAll () |
Reads all remaining data from the device, and returns it as a byte array. | |
qint64 | readLine (char *data, qint64 maxlen) |
This function reads a line of ASCII characters from the device, up to a maximum of maxSize - 1 bytes, stores the characters in data, and returns the number of bytes read. | |
QByteArray | readLine (qint64 maxlen=0) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Reads a line from the device, but no more than maxSize characters, and returns the result as a byte array. | |
virtual bool | canReadLine () const |
Returns true if a complete line of data can be read from the device; otherwise returns false . | |
void | startTransaction () |
void | commitTransaction () |
void | rollbackTransaction () |
bool | isTransactionStarted () const |
qint64 | write (const char *data, qint64 len) |
Writes at most maxSize bytes of data from data to the device. | |
qint64 | write (const char *data) |
qint64 | write (const QByteArray &data) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Writes the content of data to the device. | |
qint64 | peek (char *data, qint64 maxlen) |
QByteArray | peek (qint64 maxlen) |
qint64 | skip (qint64 maxSize) |
virtual bool | waitForReadyRead (int msecs) |
Blocks until new data is available for reading and the readyRead() signal has been emitted, or until msecs milliseconds have passed. | |
virtual bool | waitForBytesWritten (int msecs) |
For buffered devices, this function waits until a payload of buffered written data has been written to the device and the bytesWritten() signal has been emitted, or until msecs milliseconds have passed. | |
void | ungetChar (char c) |
Puts the character c back into the device, and decrements the current position unless the position is 0. | |
bool | putChar (char c) |
Writes the character c to the device. | |
bool | getChar (char *c) |
Reads one character from the device and stores it in c. | |
QString | errorString () const |
Returns a human-readable description of the last device error that occurred. | |
![]() | |
Q_INVOKABLE | QObject (QObject *parent=nullptr) |
Constructs an object with parent object parent. | |
virtual | ~QObject () |
Destroys the object, deleting all its child objects. | |
virtual bool | event (QEvent *event) |
This virtual function receives events to an object and should return true if the event e was recognized and processed. | |
virtual bool | eventFilter (QObject *watched, QEvent *event) |
Filters events if this object has been installed as an event filter for the watched object. | |
QString | objectName () const |
Q_WEAK_OVERLOAD void | setObjectName (const QString &name) |
Sets the object's name to name. | |
void | setObjectName (QAnyStringView name) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
QBindable< QString > | bindableObjectName () |
bool | isWidgetType () const |
Returns true if the object is a widget; otherwise returns false . | |
bool | isWindowType () const |
Returns true if the object is a window; otherwise returns false . | |
bool | isQuickItemType () const |
Returns true if the object is a QQuickItem; otherwise returns false . | |
bool | signalsBlocked () const noexcept |
Returns true if signals are blocked; otherwise returns false . | |
bool | blockSignals (bool b) noexcept |
If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). | |
QThread * | thread () const |
Returns the thread in which the object lives. | |
void | moveToThread (QThread *thread) |
Changes the thread affinity for this object and its children. | |
int | startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer) |
This is an overloaded function that will start a timer of type timerType and a timeout of interval milliseconds. | |
int | startTimer (std::chrono::milliseconds time, Qt::TimerType timerType=Qt::CoarseTimer) |
void | killTimer (int id) |
Kills the timer with timer identifier, id. | |
template<typename T > | |
T | findChild (const QString &aName=QString(), Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
Returns the child of this object that can be cast into type T and that is called name, or \nullptr if there is no such object. | |
template<typename T > | |
QList< T > | findChildren (const QString &aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. | |
template<typename T > | |
QList< T > | findChildren (Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
const QObjectList & | children () const |
Returns a list of child objects. | |
void | setParent (QObject *parent) |
Makes the object a child of parent. | |
void | installEventFilter (QObject *filterObj) |
Installs an event filter filterObj on this object. | |
void | removeEventFilter (QObject *obj) |
Removes an event filter object obj from this object. | |
QMetaObject::Connection | connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const |
bool | disconnect (const char *signal=nullptr, const QObject *receiver=nullptr, const char *member=nullptr) const |
bool | disconnect (const QObject *receiver, const char *member=nullptr) const |
void | dumpObjectTree () const |
Dumps a tree of children to the debug output. | |
void | dumpObjectInfo () const |
Dumps information about signal connections, etc. | |
bool | setProperty (const char *name, const QVariant &value) |
Sets the value of the object's name property to value. | |
bool | setProperty (const char *name, QVariant &&value) |
QVariant | property (const char *name) const |
Returns the value of the object's name property. | |
QList< QByteArray > | dynamicPropertyNames () const |
QBindingStorage * | bindingStorage () |
const QBindingStorage * | bindingStorage () const |
QObject * | parent () const |
Returns a pointer to the parent object. | |
bool | inherits (const char *classname) const |
Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false . | |
Protected Member Functions | |
virtual qint64 | readData (char *, qint64) override |
\reimp | |
qint64 | readLineData (char *data, qint64 maxSize) override |
\reimp | |
qint64 | skipData (qint64 maxSize) override |
\reimp | |
virtual qint64 | writeData (const char *, qint64) override |
\reimp | |
![]() | |
QIODevice (QIODevicePrivate &dd, QObject *parent=nullptr) | |
virtual qint64 | readData (char *data, qint64 maxlen)=0 |
Reads up to maxSize bytes from the device into data, and returns the number of bytes read or -1 if an error occurred. | |
virtual qint64 | readLineData (char *data, qint64 maxlen) |
Reads up to maxSize characters into data and returns the number of characters read. | |
virtual qint64 | skipData (qint64 maxSize) |
virtual qint64 | writeData (const char *data, qint64 len)=0 |
Writes up to maxSize bytes from data to the device. | |
void | setOpenMode (QIODeviceBase::OpenMode openMode) |
Sets the OpenMode of the device to openMode. | |
void | setErrorString (const QString &errorString) |
Sets the human readable description of the last device error that occurred to str. | |
![]() | |
QObject * | sender () const |
Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns \nullptr. | |
int | senderSignalIndex () const |
int | receivers (const char *signal) const |
Returns the number of receivers connected to the signal. | |
bool | isSignalConnected (const QMetaMethod &signal) const |
virtual void | timerEvent (QTimerEvent *event) |
This event handler can be reimplemented in a subclass to receive timer events for the object. | |
virtual void | childEvent (QChildEvent *event) |
This event handler can be reimplemented in a subclass to receive child events. | |
virtual void | customEvent (QEvent *event) |
This event handler can be reimplemented in a subclass to receive custom events. | |
virtual void | connectNotify (const QMetaMethod &signal) |
virtual void | disconnectNotify (const QMetaMethod &signal) |
QObject (QObjectPrivate &dd, QObject *parent=nullptr) | |
![]() | |
~QIODeviceBase ()=default | |
Properties | |
SocketOptions | socketOptions |
the socket options. | |
![]() | |
QString | objectName |
the name of this object | |
Additional Inherited Members | |
![]() | |
void | deleteLater () |
\threadsafe | |
![]() | |
static QMetaObject::Connection | connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection) |
\threadsafe | |
static QMetaObject::Connection | connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection) |
template<typename Func1 , typename Func2 > | |
static QMetaObject::Connection | connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::ContextTypeForFunctor< Func2 >::ContextType *context, Func2 &&slot, Qt::ConnectionType type=Qt::AutoConnection) |
template<typename Func1 , typename Func2 > | |
static QMetaObject::Connection | connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, Func2 &&slot) |
static bool | disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member) |
\threadsafe | |
static bool | disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member) |
static bool | disconnect (const QMetaObject::Connection &) |
Disconnect a connection. | |
template<typename Func1 , typename Func2 > | |
static bool | disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiver, Func2 slot) |
template<typename Func1 > | |
static bool | disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const QObject *receiver, void **zero) |
![]() | |
QScopedPointer< QObjectData > | d_ptr |
![]() | |
template< class T > T | qobject_cast (const QObject *object) |
Returns the given object cast to type T if the object is of type T (or of a subclass); otherwise returns \nullptr. | |
template< typename T > T | qFindChildqFindChildren (const QObject *obj, const QString &name)() |
template< typename T > QList< T > | qFindChildrenqFindChildren (const QObject *obj, const QString &name)() |
QObjectList | |
\macro Q_CLASSINFO(Name, Value) | |
The QLocalSocket class provides a local socket.
On Windows this is a named pipe and on Unix this is a local domain socket.
If an error occurs, error() 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.
Definition at line 21 of file qlocalsocket.h.
The LocalServerError enumeration represents the errors that can occur.
The most recent error can be retrieved through a call to \l QLocalSocket::error().
\value ConnectionRefusedError The connection was refused by the peer (or timed out). \value PeerClosedError 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. \value ServerNotFoundError The local socket name was not found. \value SocketAccessError The socket operation failed because the application lacked the required privileges. \value SocketResourceError The local system ran out of resources (e.g., too many sockets). \value SocketTimeoutError The socket operation timed out. \value DatagramTooLargeError The datagram was larger than the operating system's limit (which can be as low as 8192 bytes). \value ConnectionError An error occurred with the connection. \value UnsupportedSocketOperationError The requested socket operation is not supported by the local operating system. \value OperationError An operation was attempted while the socket was in a state that did not permit it. \value UnknownSocketError An unidentified error occurred.
Definition at line 29 of file qlocalsocket.h.
This enum describes the different states in which a socket can be.
\value UnconnectedState The socket is not connected. \value ConnectingState The socket has started establishing a connection. \value ConnectedState A connection is established. \value ClosingState The socket is about to close (data may still be waiting to be written).
Enumerator | |
---|---|
UnconnectedState | |
ConnectingState | |
ConnectedState | |
ClosingState |
Definition at line 44 of file qlocalsocket.h.
\value NoOptions No options have been set. \value AbstractNamespaceOption The socket will try to connect to an abstract address. This flag is specific to Linux and Android. On other platforms is ignored.
Enumerator | |
---|---|
NoOptions | |
AbstractNamespaceOption |
Definition at line 52 of file qlocalsocket.h.
Creates a new local socket.
The parent argument is passed to QObject's constructor.
Definition at line 358 of file qlocalsocket.cpp.
References d.
QLocalSocket::~QLocalSocket | ( | ) |
Destroys the socket, closing the connection if necessary.
Definition at line 370 of file qlocalsocket.cpp.
void QLocalSocket::abort | ( | ) |
Aborts the current connection and resets the socket.
Unlike disconnectFromServer(), this function immediately closes the socket, clearing any pending data in the write buffer.
Definition at line 288 of file qlocalsocket_tcp.cpp.
Referenced by ~QLocalSocket().
QBindable< QLocalSocket::SocketOptions > QLocalSocket::bindableSocketOptions | ( | ) |
Definition at line 458 of file qlocalsocket.cpp.
References d.
|
overridevirtual |
\reimp
Reimplemented from QIODevice.
Definition at line 295 of file qlocalsocket_tcp.cpp.
References QIODevice::bytesAvailable(), and d.
Referenced by QBluetoothSocketPrivateBluezDBus::bytesAvailable().
|
overridevirtual |
\reimp
Reimplemented from QIODevice.
Definition at line 301 of file qlocalsocket_tcp.cpp.
References d.
Referenced by QBluetoothSocketPrivateBluezDBus::bytesToWrite(), and QLocalClientConnection::disconnect().
|
overridevirtual |
\reimp
Reimplemented from QIODevice.
Definition at line 307 of file qlocalsocket_tcp.cpp.
References QIODevice::canReadLine(), and d.
Referenced by QBluetoothSocketPrivateBluezDBus::canReadLine().
|
overridevirtual |
Closes the I/O device for the socket and calls disconnectFromServer() to close the socket's connection.
See QIODevice::close() for a description of the actions that occur when an I/O device is closed.
Reimplemented from QIODevice.
Definition at line 313 of file qlocalsocket_tcp.cpp.
References QIODevice::close(), and d.
Referenced by abort(), and QBluetoothSocketPrivateBluezDBus::abort().
|
signal |
This signal is emitted after connectToServer() has been called and a connection has been successfully established.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.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 errorOccurred() to signal that an error occurred.
Definition at line 396 of file qlocalsocket.cpp.
References connectToServer(), QIODevice::openMode(), and setServerName().
Attempts to make a connection to serverName(). setServerName() must be called before you open the connection. Alternatively you can use connectToServer(const QString &name, OpenMode openMode);
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 errorOccurred() to signal that an error occurred.
Definition at line 180 of file qlocalsocket_tcp.cpp.
References ConnectedState, ConnectingState, d, emit, errorOccurred(), QHostAddress::LocalHost, ok, QIODevice::open(), QIODevice::openMode(), OperationError, ServerNotFoundError, QIODevice::setErrorString(), settings, state(), stateChanged(), QVariant::toUInt(), tr, and QSettings::value().
Referenced by connectToServer(), and open().
|
signal |
This signal is emitted when the socket has been disconnected.
void QLocalSocket::disconnectFromServer | ( | ) |
Attempts to close the socket.
If there is pending data waiting to be written, QLocalSocket will enter ClosingState and wait until all data has been written. Eventually, it will enter UnconnectedState and emit the disconnected() signal.
Definition at line 335 of file qlocalsocket_tcp.cpp.
References d.
QLocalSocket::LocalSocketError QLocalSocket::error | ( | ) | const |
Returns the type of error that last occurred.
Definition at line 341 of file qlocalsocket_tcp.cpp.
References ConnectionError, QAbstractSocket::ConnectionRefusedError, ConnectionRefusedError, d, QAbstractSocket::DatagramTooLargeError, DatagramTooLargeError, QAbstractSocket::HostNotFoundError, QAbstractSocket::NetworkError, PeerClosedError, qWarning, QAbstractSocket::RemoteHostClosedError, ServerNotFoundError, QAbstractSocket::SocketAccessError, SocketAccessError, QAbstractSocket::SocketResourceError, SocketResourceError, QAbstractSocket::SocketTimeoutError, SocketTimeoutError, QAbstractSocket::UnknownSocketError, UnknownSocketError, QAbstractSocket::UnsupportedSocketOperationError, and UnsupportedSocketOperationError.
|
signal |
This signal is emitted after an error occurred. The socketError parameter describes the type of error that occurred.
QLocalSocket::LocalSocketError is not a registered metatype, so for queued connections, you will have to register it with Q_DECLARE_METATYPE() and qRegisterMetaType().
Referenced by LocalSocketSignalTranslator::LocalSocketSignalTranslator(), and connectToServer().
bool QLocalSocket::flush | ( | ) |
This function writes as much as possible from the internal write buffer to the socket, without blocking.
If any data was written, this function returns true
; otherwise false is returned.
Call this function if you need QLocalSocket to start sending buffered data immediately. The number of bytes successfully written depends on the operating system. In most cases, you do not need to call this function, because QLocalSocket will start sending data automatically once control goes back to the event loop. In the absence of an event loop, call waitForBytesWritten() instead.
Definition at line 329 of file qlocalsocket_tcp.cpp.
References d.
Referenced by QLocalClientConnection::flush().
QString QLocalSocket::fullServerName | ( | ) | const |
Returns the server path that the socket is connected to.
Definition at line 471 of file qlocalsocket.cpp.
References d.
|
overridevirtual |
bool QLocalSocket::isValid | ( | ) | const |
Returns true
if the socket is valid and ready for use; otherwise returns false
.
Definition at line 374 of file qlocalsocket_tcp.cpp.
References d.
|
overridevirtual |
Equivalent to connectToServer(OpenMode mode).
The socket is opened in the given openMode to the server defined by setServerName().
Note that unlike in most other QIODevice subclasses, open() may not open the device directly. The function return false if the socket was already connected or if the server to connect to was not defined and true in any other case. The connected() or errorOccurred() signals will be emitted once the device is actually open (or the connection failed).
See connectToServer() for more details.
Definition at line 379 of file qlocalsocket.cpp.
References connectToServer(), QIODevice::isOpen(), and QIODevice::openMode().
qint64 QLocalSocket::readBufferSize | ( | ) | const |
Returns the size of the internal read buffer.
This limits the amount of data that the client can receive before you call read() or readAll(). A read buffer size of 0 (the default) means that the buffer has no size limit, ensuring that no data is lost.
Definition at line 380 of file qlocalsocket_tcp.cpp.
References d.
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.
Definition at line 427 of file qlocalsocket.cpp.
References d.
Sets the size of QLocalSocket's internal read buffer to be size bytes.
If the buffer size is limited to a certain size, QLocalSocket won't buffer more than this size of data. Exceptionally, a buffer size of 0 means that the read buffer is unlimited and all incoming data is buffered. This is the default.
This option is useful if you only read the data at certain points in time (e.g., in a real-time streaming application) or if you want to protect your socket against receiving too much data, which may eventually cause your application to run out of memory.
Definition at line 386 of file qlocalsocket_tcp.cpp.
References d.
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.
Definition at line 410 of file qlocalsocket.cpp.
References d, qWarning, and UnconnectedState.
Referenced by connectToServer().
bool QLocalSocket::setSocketDescriptor | ( | qintptr | socketDescriptor, |
LocalSocketState | socketState = ConnectedState , |
||
OpenMode | openMode = ReadWrite |
||
) |
Initializes QLocalSocket with the native socket descriptor socketDescriptor.
Returns true
if socketDescriptor is accepted as a valid socket descriptor; otherwise returns false
. The socket is opened in the mode specified by openMode, and enters the socket state specified by socketState.
Definition at line 215 of file qlocalsocket_tcp.cpp.
References child, QObject::children(), QAbstractSocket::ClosingState, ClosingState, QAbstractSocket::ConnectedState, ConnectedState, QAbstractSocket::ConnectingState, ConnectingState, d, QIODevice::open(), QIODevice::openMode(), QObject::parent(), QAbstractSocket::socketDescriptor(), socketDescriptor(), QAbstractSocket::UnconnectedState, and UnconnectedState.
void QLocalSocket::setSocketOptions | ( | SocketOptions | option | ) |
Definition at line 448 of file qlocalsocket.cpp.
References d, qWarning, and UnconnectedState.
qintptr QLocalSocket::socketDescriptor | ( | ) | const |
Returns the native socket descriptor of the QLocalSocket object if this is available; otherwise returns -1.
The socket descriptor is not available when QLocalSocket is in UnconnectedState. The type of the descriptor depends on the platform:
\list
Definition at line 255 of file qlocalsocket_tcp.cpp.
References d.
Referenced by QBluetoothSocketPrivateBluezDBus::localPort(), QBluetoothSocketPrivateBluezDBus::peerPort(), and setSocketDescriptor().
QLocalSocket::SocketOptions QLocalSocket::socketOptions | ( | ) | const |
Definition at line 442 of file qlocalsocket.cpp.
References d.
QLocalSocket::LocalSocketState QLocalSocket::state | ( | ) | const |
Returns the state of the socket.
Definition at line 482 of file qlocalsocket.cpp.
References d.
Referenced by connectToServer(), QLocalClientConnection::isConnected(), waitForConnected(), waitForDisconnected(), and waitForReadyRead().
|
signal |
This signal is emitted whenever QLocalSocket's state changes.
The socketState parameter is the new state.
QLocalSocket::SocketState is not a registered metatype, so for queued connections, you will have to register it with Q_DECLARE_METATYPE() and qRegisterMetaType().
Referenced by LocalSocketSignalTranslator::LocalSocketSignalTranslator(), and connectToServer().
|
overridevirtual |
\reimp
Reimplemented from QIODevice.
Definition at line 323 of file qlocalsocket_tcp.cpp.
References d.
Referenced by QLocalClientConnection::disconnect().
bool QLocalSocket::waitForConnected | ( | int | msecs = 30000 | ) |
Waits until the socket is connected, up to msecs milliseconds.
If the connection has been established, this function returns true
; otherwise it returns false
. In the case where it returns false
, you can call error() to determine the cause of the error.
The following example waits up to one second for a connection to be established:
If msecs is -1, this function will not time out.
Definition at line 392 of file qlocalsocket_tcp.cpp.
References ConnectedState, ConnectingState, d, and state().
Referenced by QLocalClientConnection::waitForConnection().
bool QLocalSocket::waitForDisconnected | ( | int | msecs = 30000 | ) |
Waits until the socket has disconnected, up to msecs milliseconds.
If the connection was successfully disconnected, this function returns true
; otherwise it returns false
(if the operation timed out, if an error occurred, or if this QLocalSocket is already disconnected). In the case where it returns false
, you can call error() to determine the cause of the error.
The following example waits up to one second for a connection to be closed:
If msecs is -1, this function will not time out.
Definition at line 401 of file qlocalsocket_tcp.cpp.
References d, qWarning, state(), and UnconnectedState.
|
overridevirtual |
This function blocks until data is available for reading and the \l{QIODevice::}{readyRead()} signal has been emitted.
The function will timeout after msecs milliseconds; the default timeout is 30000 milliseconds.
The function returns true
if data is available for reading; otherwise it returns false
(if an error occurred or the operation timed out).
Reimplemented from QIODevice.
Definition at line 411 of file qlocalsocket_tcp.cpp.
References d, state(), and UnconnectedState.
|
readwrite |
the socket options.
Options must be set while the socket is in \l{UnconnectedState} state.
Definition at line 133 of file qlocalsocket.h.