Home · All Namespaces · All Classes · Grouped Classes · Modules · Functions codeless banner

QIrSocket Class Reference

The QIrSocket class represents an Infrared client socket. More...

    #include <QIrSocket>

Inherits QIODevice.

Public Types

Public Functions

Signals

Additional Inherited Members


Detailed Description

The QIrSocket class represents an Infrared client socket.

At any time, the QIrSocket has a state (returned by state()). Upon creation, the initial state is QIrSocket::UnconnectedState.

After calling connect(), the socket enters the QIrSocket::ConnectingState. If connection is established, the socket enters QIrSocket::ConnectedState and emits connected().

If an error occurs at any time, the error() signal is emitted. Whenever the state changes, stateChanged() is emitted. For convenience, isValid() returns true if the socket is ready for reading and writing.

Read or write data to/from the socket by calling read() or write(), or use the convenience functions readLine() and readAll(). QIrSocket also inherits getChar(), putChar(), and ungetChar() from QIODevice, which work on single bytes. For every chunk of data that has been written to the socket, the bytesWritten() signal is emitted.

The readyRead() signal is emitted every time a new chunk of data has arrived. bytesAvailable() then returns the number of bytes that are available for reading. Typically, you would connect the readyRead() signal to a slot and read all available data there. If you don't read all the data at once, the remaining data will still be available later, and any new incoming data will be appended to QIrSocket's internal read buffer. To limit the size of the read buffer, call setReadBufferSize().

To close the socket, call disconnect(). Once disconnect() is called, QIrSocket enters the QIrSocket::ClosingState and emits the stateChanged() signal. After all pending data has been written to the socket, QIrSocket actually closes the socket, enters the QIrSocket::ClosedState, and emits disconnected(). If no data is pending when disconnect() is called, the connection is disconnected immediately. If you want to abort a connection immediately, discarding all pending data, call abort() instead.

QIrSocket provides a set of functions that suspend the calling thread until certain signals are emitted. These functions can be used to implement blocking sockets:

See also QIrServer.


Member Type Documentation

enum QIrSocket::SocketError

Error that last occurred on the infrared socket.

ConstantValueDescription
QIrSocket::NoError0No error has occurred.
QIrSocket::AccessError1The client has inadequate permissions to access the socket.
QIrSocket::ResourceError2The kernel has run out of sockets.
QIrSocket::BusyError3Another connect is in progress or device is busy.
QIrSocket::HostUnreachableError4The host is unreachable. This can be caused by an invalid destination address or remote device not being present.
QIrSocket::ServiceUnavailableError5The host was found, but did not provide the target service.
QIrSocket::ConnectionRefused6The remote host has refused a connection.
QIrSocket::NetworkError7A network error has occurred, e.g. device moved out of range.
QIrSocket::TimeoutError8Operation has timed out.
QIrSocket::RemoteHostClosedError9Remote host has closed the connection.
QIrSocket::BusyError3The system is busy.
QIrSocket::HostUnreachableError4The remote host could not be reached.
QIrSocket::UnsupportedOperationError10The operation is not supported.
QIrSocket::AddressInUseError11Address is currently in use.
QIrSocket::AddressNotAvailableError12Address is not available.
QIrSocket::UnknownError13Unknown error has occurred.

enum QIrSocket::SocketState

State of the infrared socket.

ConstantValueDescription
QIrSocket::UnconnectedState0The socket is not connected.
QIrSocket::ConnectingState1The socket is being connected.
QIrSocket::ConnectedState2The socket is connected.
QIrSocket::BoundState3The socket has been bound.
QIrSocket::ClosingState4The socket is being closed.


Member Function Documentation

QIrSocket::QIrSocket ( QObject * parent = 0 )

Constructs a new QIrSocket with parent. The socket is not connected. The parent specifies the QObject parent.

QIrSocket::~QIrSocket ()

Deconstructs a QIrSocket. If the socket is in any state other than UnconnectedState, the current connection is aborted.

void QIrSocket::abort ()

Aborts the current connection and resets the socket. Unlike disconnect(), this function immediately closes the socket, clearing any pending data in the write buffer.

See also disconnect() and close().

qint64 QIrSocket::bytesAvailable () const   [virtual]

Returns the number of bytes that are waiting to be read.

Reimplemented from QIODevice.

See also bytesToWrite() and read().

qint64 QIrSocket::bytesToWrite () const   [virtual]

Returns the number of bytes which are pending to be written.

Reimplemented from QIODevice.

See also bytesAvailable() and write().

bool QIrSocket::canReadLine () const   [virtual]

Returns true if a line of data can be read from the socket; otherwise returns false.

Reimplemented from QIODevice.

See also readLine().

void QIrSocket::close ()   [virtual]

Closes the socket. This is the same as disconnect()

Reimplemented from QIODevice.

See also abort() and disconnect().

bool QIrSocket::connect ( const QByteArray & service, quint32 remote )

Attempts to open an Infrared connection between the local device and the remote device with address remote. The underlying channel will be selected based on service parameter. The service parameter will be looked up in the remote device's IAS Database. This function should generally return immediately, and the socket will enter into the ConnectingState.

The function returns true if the connection process could be started, and false otherwise.

Note that the connection could still fail, the state of the socket will be sent in the stateChanged() signal.

NOTE: Under LINUX, you can pass 0 for the remote parameter. In this case, the kernel will select the first available device which contains an IAS entry that matches the service parameter.

See also state(), connected(), and waitForConnected().

void QIrSocket::connected ()   [signal]

This signal is emitted once the connect() has been called and the socket has been successfully connected.

See also connect() and disconnected().

bool QIrSocket::disconnect ()   [virtual]

Attempts to close the socket. If there is pending data waiting to be written, the socket will enter ClosingState and wait until all data has been written. Eventually it will enter UnconnectedState and emit the disconnected() signal.

Returns true on successful completion of the request; otherwise returns false.

See also close().

void QIrSocket::disconnected ()   [signal]

This signal is emitted when the socket has been disconnected.

See also connect(), disconnect(), and abort().

SocketError QIrSocket::error () const

Returns the last error that has occurred.

See also state().

void QIrSocket::error ( QIrSocket::SocketError 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 has occurred.

See also error() and errorString().

bool QIrSocket::flush ()   [virtual]

This function writes as much as possible from the internal write buffer to the underlying network socket, without blocking. If any data was written, this function returns true; otherwise false is returned.

See also write() and waitForBytesWritten().

qint64 QIrSocket::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.

See also setReadBufferSize() and read().

quint32 QIrSocket::remoteAddress () const

Returns the address of the remote device this socket is connected to. If the socket is not connected, this returns 0.

See also connect().

void QIrSocket::setReadBufferSize ( qint64 size )

Sets the capacity of QIrSocket's internal read buffer to be size bytes. If size is 0 the buffer has unlimited capacity. This is the default.

See also readBufferSize().

bool QIrSocket::setSocketDescriptor ( int socketDescriptor, QIrSocket::SocketState state, QIODevice::OpenMode openMode = QIODevice::ReadWrite )

Initializes the QIrSocket with the native descriptor socketDescriptor. The socket is put into the state and opened in openMode.

Returns true on successful completion of the request; otherwise returns false.

See also socketDescriptor().

int QIrSocket::socketDescriptor () const

Returns the socket descriptor for the socket if the socket is currently active (e.g. not in UnconnectedState). Otherwise returns -1.

See also setSocketDescriptor() and state().

SocketState QIrSocket::state () const

Returns the state of the socket.

See also error().

void QIrSocket::stateChanged ( QIrSocket::SocketState socketState )   [signal]

This signal is emitted when the state of the socket has changed. The socketState parameter holds the new state.

See also state().

bool QIrSocket::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 returns false. In the case where it returns false, you can call error() to determine the cause of the error.

This is a blocking function call. Its use is not advised in a single-threaded GUI application, since the whole application will stop responding until the function returns. waitForNewConnected() is mostly useful when there is no event loop available.

See also connect() and connected().

bool QIrSocket::waitForDisconnected ( int msecs = 30000 )

Waits until the socket is disconnected, up to msecs milliseconds. If the connection has been terminated, this function returns true; otherwise returns false. In the case where it returns false, you can call error() to determine the cause of the error.

This is a blocking function call. Its use is not advised in a single-threaded GUI application, since the whole application will stop responding until the function returns. waitForDisconnected() is mostly useful when there is no event loop available.

See also disconnect(), close(), and disconnected().


Copyright © 2009 Nokia Trademarks
Qt Extended 4.4.3