Movatterモバイル変換


[0]ホーム

URL:


We bake cookies in your browser for a better experience. Using this site means that you consent.Read More

Menu

Qt Documentation

QCopChannel Class

TheQCopChannel class provides communication capabilities between clients inQt for Embedded Linux.More...

Header:#include <QCopChannel>
Inherits:QObject

Public Functions

QCopChannel(const QString & channel, QObject * parent = 0)
virtual~QCopChannel()
QStringchannel() const
virtual voidreceive(const QString & message, const QByteArray & data)
  • 29 public functions inherited fromQObject

Signals

voidreceived(const QString & message, const QByteArray & data)

Static Public Members

boolflush()
boolisRegistered(const QString & channel)
boolsend(const QString & channel, const QString & message, const QByteArray & data)
boolsend(const QString & channel, const QString & message)
  • 7 static public members inherited fromQObject

Additional Inherited Members

  • 1 property inherited fromQObject
  • 1 public slot inherited fromQObject
  • 8 protected functions inherited fromQObject

Detailed Description

TheQCopChannel class provides communication capabilities between clients inQt for Embedded Linux.

Note that this class is only available inQt for Embedded Linux.

The Qt COmmunication Protocol (QCOP) is a many-to-many protocol for transferring messages across registered channels. A channel is registered by name, and anyone who wants to can listen to the channel as well as send messages through it. The QCOP protocol allows clients to communicate both within the same address space and between different processes.

To send messages to a given channel,QCopChannel provides the staticsend() function. Using this function alone, the messages are queued until Qt re-enters the event loop. To immediately flush all queued messages to the registered listeners, call the staticflush() function.

To listen to the traffic on a given channel, you typically instantiate aQCopChannel object for the given channel and connect to itsreceived() signal that is emitted whenever there is incoming data. Use the staticisRegistered() function to query the server for the existence of a given channel.QCopChannel provides thechannel() function returning the name of thisQCopChannel object's channel.

In additon,QCopChannel provides the virtualreceive() function that can be reimplemented to filter the incoming messages and data. The default implementation simply emits thereceived() signal.

See alsoQWSServer,QWSClient, andQt for Embedded Linux Architecture.

Member Function Documentation

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

Constructs aQCopChannel object for the specifiedchannel, with the givenparent. Once created, the channel is registered by the server.

See alsoisRegistered() andchannel().

[virtual]QCopChannel::~QCopChannel()

Destroys thisQCopChannel object.

The server is notified that this particular listener has closed its connection. The server will keep the channel open until the last registered listener detaches.

See alsoisRegistered() andchannel().

QString QCopChannel::channel() const

Returns the name of this object's channel.

See alsoisRegistered().

[static]bool QCopChannel::flush()

Flushes all queued messages to the registered listeners.

Note that this function returns false if noQApplication has been constructed, otherwise it returns true.

This function was introduced in Qt 4.2.

See alsosend().

[static]bool QCopChannel::isRegistered(constQString & channel)

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

See alsochannel() andsend().

[virtual]void QCopChannel::receive(constQString & message, constQByteArray & data)

Processes the incomingmessage anddata.

This function is called by the server when this object's channel receives new messages. Note that the default implementation simply emits thereceived() signal; reimplement this function to process the incomingmessage anddata.

Note that the format of the givendata 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. For example:

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

The above code assumes that themessage is a DCOP-style function signature and thedata contains the function's arguments.

See alsosend(),channel(), andreceived().

[signal]void QCopChannel::received(constQString & message, constQByteArray & data)

This signal is emitted whenever this object's channel receives new messages (i.e., it is emitted by thereceive() function), passing the incomingmessage anddata as parameters.

See alsoreceive() andchannel().

[static]bool QCopChannel::send(constQString & channel, constQString & message, constQByteArray & data)

Sends the givenmessage on the specifiedchannel with the givendata. The message will be distributed to all clients subscribed to the channel. Returns true if the message is sent successfully; otherwise returns false.

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 thatQDataStream provides a convenient way to fill the byte array with auxiliary data. For example:

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

In the code above the channel is"System/Shell". Themessage 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)" wheretypes 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 alsoreceive() andisRegistered().

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

This is an overloaded function.

© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.


[8]ページ先頭

©2009-2025 Movatter.jp