Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Tous les espaces de nom  ·  Toutes les classes  ·  Classes principales  ·  Annotées  ·  Classes groupées  ·  Modules  ·  Fonctions  · 

QCopChannel Class Reference
[QtGui module]

The QCopChannel class provides communication capabilities between clients in Qt for Embedded Linux. More...

 #include <QCopChannel>

Inherits QObject.

Public Functions

  • QCopChannel ( const QString & channel, QObject * parent = 0 )
  • virtual ~QCopChannel ()
  • QString channel () const
  • virtual void receive ( const QString & message, const QByteArray & data )
  • 29 public functions inherited from QObject

Signals

  • void received ( const QString & message, const QByteArray & data )

Static Public Members

  • bool flush ()
  • bool isRegistered ( const QString & channel )
  • bool send ( const QString & channel, const QString & message, const QByteArray & data )
  • bool send ( const QString & channel, const QString & message )
  • 5 static public members inherited from QObject

Additional Inherited Members

  • 1 property inherited from QObject
  • 1 public slot inherited from QObject
  • 7 protected functions inherited from QObject

Detailed Description

The QCopChannel class provides communication capabilities between clients in Qt for Embedded Linux.

Note that this class is only available in Qt 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 static send() 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 static flush() function.

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

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

See also QWSServer, QWSClient, and Qt for Embedded Linux Architecture.


Member Function Documentation

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

Constructs a QCopChannel object for the specified channel, with the given parent. Once created, the channel is registered by the server.

See also isRegistered() and channel().

QCopChannel::~QCopChannel ()   [virtual]

Destroys this QCopChannel 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 also isRegistered() and channel().

QString QCopChannel::channel () const

Returns the name of this object's channel.

See also isRegistered().

bool QCopChannel::flush ()   [static]

Flushes all queued messages to the registered listeners.

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

This function was introduced in Qt 4.2.

See also send().

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 send().

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

Processes the incoming message and data.

This function is called by the server when this object's channel receives new messages. Note that the default implementation simply emits the received() signal; reimplement this function to process the incoming message and data.

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. For 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 {
         ...
     }
 }

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

See also send(), channel(), and received().

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

This signal is emitted whenever this object's channel receives new messages (i.e., it is emitted by the receive() function), passing the incoming message and data as parameters.

See also receive() and channel().

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. 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 that QDataStream 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". 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() and isRegistered().

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

This is an overloaded member function, provided for convenience.

Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 53
  2. Les développeurs ignorent-ils trop les failles découvertes dans leur code ? Prenez-vous en compte les remarques des autres ? 17
  3. BlackBerry 10 : premières images du prochain OS de RIM qui devrait intégrer des widgets et des tuiles inspirées de Windows Phone 0
  4. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
  5. Adieu qmake, bienvenue qbs : Qt Building Suite, un outil déclaratif et extensible pour la compilation de projets Qt 17
  6. Apercevoir la troisième dimension ou l'utilisation multithreadée d'OpenGL dans Qt, un article des Qt Quarterly traduit par Guillaume Belz 0
  7. La rubrique Qt a besoin de vous ! 1
Page suivante

Le blog Digia au hasard

Logo

Créer des applications avec un style Metro avec Qt, exemples en QML et C++, un article de Digia Qt traduit par Thibaut Cuvelier

Le blog Digia est l'endroit privilégié pour la communication sur l'édition commerciale de Qt, où des réponses publiques sont apportées aux questions les plus posées au support. Lire l'article.

Communauté

Ressources

Liens utiles

Contact

  • Vous souhaitez rejoindre la rédaction ou proposer un tutoriel, une traduction, une question... ? Postez dans le forum Contribuez ou contactez-nous par MP ou par email (voir en bas de page).

Qt dans le magazine

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt 4.4
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web