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

# QSocketNotifier Class Reference
[QtCore module]

The QSocketNotifier class provides support for monitoring activity on a file descriptor. More...

    #include <QSocketNotifier>

Inherits QObject.

- List of all members, including inherited members
- Qt 3 support members

### Public Types

- enum Type { Read, Write, Exception }

### Public Functions

- QSocketNotifier ( int socket, Type type, QObject * parent = 0 )
- ~QSocketNotifier ()
- bool isEnabled () const
- int socket () const
- Type type () const

- 28 public functions inherited from QObject

### Public Slots

- void setEnabled ( bool enable )

- 1 public slot inherited from QObject

### Signals

- void activated ( int socket )

- 1 signal inherited from QObject

### Additional Inherited Members

- 1 property inherited from QObject
- 4 static public members inherited from QObject
- 7 protected functions inherited from QObject

## Detailed Description

The QSocketNotifier class provides support for monitoring activity on a file descriptor.

The QSocketNotifier makes it possible to integrate Qt's event loop with other event loops based on file descriptors. For example, the QtCorba Solution uses it to process CORBA events. File descriptor action is detected in Qt's main event loop (QCoreApplication::exec()).

Once you have opened a device using a low-level (usually platform-specific) API, you can create a socket notifier to monitor the file descriptor. You can then connect the activated() signal to the slot you want to be called whenever an event occurs.

Although the class is called QSocketNotifier, it is normally used for other types of devices than sockets. QTcpSocket and QUdpSocket provide notification through signals, so there is normally no need to use a QSocketNotifier on them.

There are three types of socket notifiers: read, write, and exception. You must specify one of these in the constructor.

The type specifies when the activated() signal is to be emitted:

1. QSocketNotifier::Read - There is data to be read.
2. QSocketNotifier::Write - Data can be written.
3. QSocketNotifier::Exception - An exception has occurred. We recommend against using this.

Note: If you need to monitor both reads and writes for the same file descriptor, you must create two socket notifiers. It is not possible to install two socket notifiers of the same type (Read, Write, Exception) on the same socket.

See also QFile, QProcess, QTcpSocket, and QUdpSocket.

## Member Type Documentation

### enum QSocketNotifier::Type

The socket notifier can be used to inform the application of the following types of event:

Constant | Value | Description
--- | --- | ---
`QSocketNotifier::Read` | `0` | There is incoming data.
`QSocketNotifier::Write` | `1` | Data can be written.
`QSocketNotifier::Exception` | `2` | An exception has occurred.

## Member Function Documentation

### QSocketNotifier::QSocketNotifier ( int socket, Type type, QObject * parent = 0 )

Constructs a socket notifier with the given parent. It enables the socket, and watches for events of the given type.

It is generally advisable to explicitly enable or disable the socket notifier, especially for write notifiers.

See also setEnabled() and isEnabled().

### QSocketNotifier::~QSocketNotifier ()

Destroys the socket notifier.

### void QSocketNotifier::activated ( int socket ) `[signal]`

This signal is emitted under certain conditions specified by the notifier type():

1. QSocketNotifier::Read - There is data to be read (socket read event).
2. QSocketNotifier::Write - Data can be written (socket write event).
3. QSocketNotifier::Exception - An exception has occurred (socket exception event).

The socket is the socket identifier.

See also type() and socket().

### bool QSocketNotifier::isEnabled () const

Returns true if the notifier is enabled; otherwise returns false.

See also setEnabled().

### void QSocketNotifier::setEnabled ( bool enable ) `[slot]`

If enable is true, the notifier is enabled; otherwise the notifier is disabled.

The notifier is enabled by default.

If the notifier is enabled, it emits the activated() signal whenever a socket event corresponding to its type occurs. If it is disabled, it ignores socket events (the same effect as not creating the socket notifier).

Write notifiers should normally be disabled immediately after the activated() signal has been emitted; see discussion of write notifiers in the class description above.

See also isEnabled() and activated().

### int QSocketNotifier::socket () const

Returns the socket identifier specified to the constructor.

See also type().

### Type QSocketNotifier::type () const

Returns the socket event type specified to the constructor.

See also socket().