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

QCopChannel Class Reference
[QtGui module]

The QCopChannel class provides communication capabilities between clients. More...

#include <QCopChannel>

Inherits QObject.

Public Functions

Signals

Static Public Members

Additional Inherited Members


Detailed Description

The QCopChannel class provides communication capabilities between clients.

QCOP is a many-to-many communication protocol for transferring messages on various channels. A channel is identified by a name, and anyone who wants to can listen to it. The QCOP protocol allows clients to communicate both within the same address space and between different processes, but it is currently only available for Qtopia Core (on X11 and Windows we are exploring the use of existing standards such as DCOP and COM).

Typically, QCopChannel is either used to send messages to a channel using the provided static functions, or to listen to the traffic on a channel by deriving from the class to take advantage of the provided functionality for receiving messages.

QCopChannel provides a couple of static functions which are usable without an object: The send() function, which sends the given message and data on the specified channel, and the isRegistered() function which queries the server for the existence of the given channel.

In addition, the QCopChannel class provides the channel() function which returns the name of the object's channel, the virtual receive() function which allows subclasses to process data received from their channel, and the received() signal which is emitted with the given message and data when a QCopChannel subclass receives a message from its channel.

See also QWSClient and Running Applications.


Member Function Documentation

QCopChannel::QCopChannel ( const QString & channel, QObject * parent = 0 )

Constructs a QCop channel with the given parent, and registers it with the server using the given channel name.

See also isRegistered() and channel().

QCopChannel::~QCopChannel ()   [virtual]

Destroys the client's end of the channel and notifies the server that the client has closed its connection. The server will keep the channel open until the last registered client detaches.

See also QCopChannel().

QString QCopChannel::channel () const

Returns the name of the channel.

See also QCopChannel().

bool QCopChannel::isRegistered ( const QString & channel )   [static]

Queries the server for the existence of the given channel. Returns true if the channel is registered; otherwise returns false.

See also channel() and QCopChannel().

void QCopChannel::receive ( const QString & message, const QByteArray & data )   [virtual]

This virtual function allows subclasses of QCopChannel to process the given message and data received from their channel. The default implementation emits the received() signal.

Note that the format of the given data has to be well defined in order to extract the information it contains. In addition, it is recommended to use the DCOP convention. This is not a requirement, but you must ensure that the sender and receiver agree on the argument types.

Example:

    void MyClass::receive(const QString &message, const QByteArray &data)
    {
        QDataStream in(data);
        if (message == "execute(QString,QString)") {
            QString cmd;
            QString arg;
            in >> cmd >> arg;
            ...
        } else if (message == "delete(QString)") {
            QString fileName;
            in >> fileName;
            ...
        } else {
            ...
        }
    }

This example assumes that the message is a DCOP-style function signature and the data contains the function's arguments.

See also send().

void QCopChannel::received ( const QString & message, const QByteArray & data )   [signal]

This signal is emitted with the given message and data whenever the receive() function gets incoming data.

See also receive().

bool QCopChannel::send ( const QString & channel, const QString & message, const QByteArray & data )   [static]

Sends the given message on the specified channel with the given data. The message will be distributed to all clients subscribed to the channel.

It is recommended to use the DCOP convention. This is not a requirement, but you must ensure that the sender and receiver agree on the argument types.

Note that QDataStream provides a convenient way to fill the byte array with auxiliary data.

Example:

    QByteArray data;
    QDataStream out(&data, QIODevice::WriteOnly);
    out << QString("cat") << QString("file.txt");
    QCopChannel::send("System/Shell", "execute(QString,QString)", data);

Here the channel is "System/Shell". The message is an arbitrary string, but in the example we've used the DCOP convention of passing a function signature. Such a signature is formatted as "functionname(types)" where types is a list of zero or more comma-separated type names, with no whitespace, no consts and no pointer or reference marks, i.e. no "*" or "&".

See also receive().

bool QCopChannel::send ( const QString & channel, const QString & message )   [static]

This is an overloaded member function, provided for convenience.

Sends the given message on the specified channel. The message will be distributed to all clients subscribed to the channel.


Copyright © 2006 Trolltech Trademarks
Qt 4.1.3