Home · All Classes · Main Classes · Grouped Classes · Modules · Functions

QLocalSocket Class Reference
[QtNetwork module]

The QLocalSocket class provides a local socket. More...

 #include <QLocalSocket>

Inherits QIODevice.

This class was introduced in Qt 4.4.

Public Types

Public Functions

Signals

Protected Functions

Additional Inherited Members


Detailed Description

The QLocalSocket class provides a local socket.

On Windows this is a named pipe and on Unix this 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.

Note that this feature is not supported on Windows CE.

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().

ConstantValueDescription
QLocalSocket::ConnectionRefusedErrorQAbstractSocket::ConnectionRefusedErrorThe connection was refused by the peer (or timed out).
QLocalSocket::PeerClosedErrorQAbstractSocket::RemoteHostClosedErrorThe 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::ServerNotFoundErrorQAbstractSocket::HostNotFoundErrorThe local socket name was not found.
QLocalSocket::SocketAccessErrorQAbstractSocket::SocketAccessErrorThe socket operation failed because the application lacked the required privileges.
QLocalSocket::SocketResourceErrorQAbstractSocket::SocketResourceErrorThe local system ran out of resources (e.g., too many sockets).
QLocalSocket::SocketTimeoutErrorQAbstractSocket::SocketTimeoutErrorThe socket operation timed out.
QLocalSocket::DatagramTooLargeErrorQAbstractSocket::DatagramTooLargeErrorThe datagram was larger than the operating system's limit (which can be as low as 8192 bytes).
QLocalSocket::ConnectionErrorQAbstractSocket::NetworkErrorAn error occurred with the connection.
QLocalSocket::UnsupportedSocketOperationErrorQAbstractSocket::UnsupportedSocketOperationErrorThe requested socket operation is not supported by the local operating system.
QLocalSocket::UnknownSocketErrorQAbstractSocket::UnknownSocketErrorAn unidentified error occurred.

enum QLocalSocket::LocalSocketState

This enum describes the different states in which a socket can be.

ConstantValueDescription
QLocalSocket::UnconnectedStateQAbstractSocket::UnconnectedStateThe socket is not connected.
QLocalSocket::ConnectingStateQAbstractSocket::ConnectingStateThe socket has started establishing a connection.
QLocalSocket::ConnectedStateQAbstractSocket::ConnectedStateA connection is established.
QLocalSocket::ClosingStateQAbstractSocket::ClosingStateThe socket is about to close (data may still be waiting to be written).

See also QLocalSocket::state().


Member Function Documentation

QLocalSocket::QLocalSocket ( QObject * parent = 0 )

Creates a new local socket. The parent argument is passed to QObject's constructor.

QLocalSocket::~QLocalSocket ()

Destroys the socket, closing the connection if necessary.

void QLocalSocket::abort ()

qint64 QLocalSocket::bytesAvailable () const   [virtual]

qint64 QLocalSocket::bytesToWrite () const   [virtual]

bool QLocalSocket::canReadLine () const   [virtual]

void QLocalSocket::close ()   [virtual]

void QLocalSocket::connectToServer ( const QString & name, OpenMode openMode = ReadWrite )

void QLocalSocket::connected ()   [signal]

This signal is emitted after connectToServer() has been called and a connection has been successfully established.

See also connectToServer() and disconnected().

void QLocalSocket::disconnectFromServer ()

void QLocalSocket::disconnected ()   [signal]

This signal is emitted when the socket has been disconnected.

See also connectToServer(), disconnectFromServer(), abort(), and connected().

LocalSocketError QLocalSocket::error () const

void QLocalSocket::error ( QLocalSocket::LocalSocketError socketError )   [signal]

This is an overloaded member function, provided for convenience.

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_REGISTER_METATYPE.

See also error() and errorString().

bool QLocalSocket::flush ()

QString QLocalSocket::fullServerName () const

Returns the server path that the socket is connected to.

Note: This is platform specific

See also connectToServer() and serverName().

bool QLocalSocket::isValid () const

qint64 QLocalSocket::readBufferSize () const

See also setReadBufferSize().

qint64 QLocalSocket::readData ( char *, qint64 )   [virtual protected]

QString QLocalSocket::serverName () const

Returns the name of the peer as specified by connectToServer(), or an empty QString if connectToServer() has not been called or it failed.

See also connectToServer() and fullServerName().

void QLocalSocket::setReadBufferSize ( qint64 size )

See also readBufferSize().

bool QLocalSocket::setSocketDescriptor ( quintptr socketDescriptor, LocalSocketState socketState = ConnectedState, OpenMode openMode = ReadWrite )

See also socketDescriptor().

quintptr QLocalSocket::socketDescriptor () const

See also setSocketDescriptor().

LocalSocketState QLocalSocket::state () const

Returns the state of the socket.

See also error().

void QLocalSocket::stateChanged ( QLocalSocket::LocalSocketState socketState )   [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_REGISTER_METATYPE.

See also state().

bool QLocalSocket::waitForBytesWritten ( int msecs = 30000 )   [virtual]

bool QLocalSocket::waitForConnected ( int msecs = 30000 )

bool QLocalSocket::waitForDisconnected ( int msecs = 30000 )

bool QLocalSocket::waitForReadyRead ( int msecs = 30000 )   [virtual]

qint64 QLocalSocket::writeData ( const char *, qint64 )   [virtual protected]


Copyright © 2008 Trolltech Trademarks
Qt 4.4.0