QCopChannel(3qt)

NAME
QCopChannel - Communication capabilities between several clients

SYNOPSIS
#include <qcopchannel_qws.h>

Inherits QObject.

  Public Members
QCopChannel ( const QCString & channel, QObject * parent = 0, const char * name = 0 )
virtual ~QCopChannel ()
QCString channel () const
virtual void receive ( const QCString & msg, const QByteArray & data )

  Signals
void received ( const QCString & msg, const QByteArray & data )

  Static Public Members
bool isRegistered ( const QCString & channel )
bool send ( const QCString & channel, const QCString & msg )
bool send ( const QCString & channel, const QCString & msg, const QByteArray & data )

DESCRIPTION
The QCopChannel class provides communication capabilities between several clients.

The Qt Cop (QCOP) is a COmmunication Protocol, allowing clients to communicate both within the same address space and between different processes.

Currently, this facility is only available on Qt/Embedded. On X11 and Windows we are exploring the use of existing standards such as DCOP and COM.

QCopChannel provides send() and isRegistered() which are static functions usable without an object.

The channel() function returns the name of the channel.

In order to listen to the traffic on a channel, you should either subclass QCopChannel and reimplement receive(), or connect() to the received() signal.

MEMBER FUNCTION DOCUMENTATION

QCopChannel::QCopChannel ( const QCString & channel, QObject * parent = 0, const char * name = 0 )
Constructs a QCop channel and registers it with the server using the name channel. The standard parent and name arguments are passed on to the QObject constructor.

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.

QCString QCopChannel::channel () const
Returns the name of the channel.

bool QCopChannel::isRegistered ( const QCString & channel ) [static]
Queries the server for the existence of channel.

Returns TRUE if channel is registered; otherwise returns FALSE.

void QCopChannel::receive ( const QCString & msg, const QByteArray & data ) [virtual]
This virtual function allows subclasses of QCopChannel to process data received from their channel.

The default implementation emits the received() signal.

Note that the format of data has to be well defined in order to extract the information it contains.

Example:

    void MyClass::receive( const QCString &msg, const QByteArray &data )
    {
        QDataStream stream( data, IO_ReadOnly );
        if ( msg == "execute(QString,QString)" ) {
            QString cmd, arg;
            stream >> cmd >> arg;
            ...
        } else if ( msg == "delete(QString)" ) {
            QString filenname;
            stream >> filename;
            ...
        } else ...
    }
This example assumes that the msg is a DCOP-style function signature and the data contains the function's arguments. (See send().)

Using the DCOP convention is a recommendation, but not a requirement. Whatever convention you use the sender and receiver must agree on the argument types.

See also send().

void QCopChannel::received ( const QCString & msg, const QByteArray & data ) [signal]
This signal is emitted with the msg and data whenever the receive() function gets incoming data.

bool QCopChannel::send ( const QCString & channel, const QCString & msg, const QByteArray & data ) [static]
Send the message msg on channel channel with data data. The message will be distributed to all clients subscribed to the channel.

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

Example:

    QByteArray ba;
    QDataStream stream( ba, IO_WriteOnly );
    stream << QString("cat") << QString("file.txt");
    QCopChannel::send( "System/Shell", "execute(QString,QString)", ba );
Here the channel is "System/Shell". The msg 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 "&".

Using the DCOP convention is a recommendation, but not a requirement. Whatever convention you use the sender and receiver must agree on the argument types.

See also receive().

bool QCopChannel::send ( const QCString & channel, const QCString & msg ) [static]
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Send the message msg on channel channel. The message will be distributed to all clients subscribed to the channel.

See also receive().

SEE ALSO
http://doc.trolltech.com/qcopchannel.html http://www.trolltech.com/faq/tech.html

COPYRIGHT
Copyright 1992-2001 Trolltech AS, http://www.trolltech.com. See the license file included in the distribution for a complete license statement.

AUTHOR
Generated automatically from the source code.

BUGS
If you find a bug in Qt, please report it as described in http://doc.trolltech.com/bughowto.html. Good bug reports help us to help you. Thank you.

The definitive Qt documentation is provided in HTML format; it is located at $QTDIR/doc/html and can be read using Qt Assistant or with a web browser. This man page is provided as a convenience for those users who prefer man pages, although this format is not officially supported by Trolltech.

If you find errors in this manual page, please report them to qt-bugs@trolltech.com. Please include the name of the manual page (qcopchannel.3) and the Qt version (3.3.4).