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  ·  Toutes les classes  ·  Toutes les fonctions  ·  Vues d'ensemble  · 

Tutorial: Qt Extended IPC Server

Files:

The Qt Extended IPC Tutorial demonstrates the use of QtopiaIpcAdaptor, which is the fundamental class of the Qt Extended IPC system. This example demonstrates the basics of sending and receiving messages between different applications. For the other part of this tutorial, see Tutorial: Qt Extended IPC Client.

The cannonserver application starts and begins listening on an IPC channel QPE/CannonExample. When it receives a cannon shoot order, it randomly decides whether the cannon has hit something or missed completely. It then broadcasts the results of the shot on the same channel and exits.

CannonListener Class Definition

    class CannonListener : public QtopiaIpcAdaptor
    {
        Q_OBJECT

    public:
        CannonListener(QObject *parent = 0);

    public slots:
        void shootCannon(int);

    signals:
        void missed();
        void hit();
    };

The CannonListener class inherits QtopiaIpcAdaptor which is used to send and receive messages between Qt Extended based applications. There are two signals that CannonListener class emits, and a one slot. When a message of type shootCannon() arrives, the shootCannon slot will be called in CannonListener automatically. Similarly, when the CannonListener emits a signal, a message with the same signature will be sent over the IPC channel.

CannonListener Class Implementation

The constructor contains a single call to publishAll(). This tells the Qt Extended IPC system to make the necessary connections between the IPC messages and slots in the CannonListener class. In this example we want all messages with the same signature as the public slots to be hooked up automatically. All signals sent by this class will also be automatically broadcast to the remote clients whenever CannonListener emits the defined signal.

    CannonListener::CannonListener(QObject *parent)
        : QtopiaIpcAdaptor("QPE/CannonExample", parent)
    {
        publishAll(QtopiaIpcAdaptor::SignalsAndSlots);
    }

The shootCannon() slot will be automatically called whenever a message with the same signature arrives. The power parameter will hold the message arguments. We roll a simple dice to figure out whether the cannon hit or missed and emit a corresponding signal. This will result in the Qt Extended IPC system broadcasting and IPC message with the same signature. Finally we delete the CannonListener object by using deleteLater(). This will result in the application terminating.

    void CannonListener::shootCannon(int power)
    {
        int pwr = power % 100;
        int roll = qrand() % 100;

        if (pwr >= roll)
            emit hit();
        else
            emit missed();

        deleteLater();
    }

Building the Cannon Listener application.

To install and run the Cannon Listener application, carry out the following steps.

  1. Create a new directory (e.g. $HOME/src/cannonserver) and copy all the example files to that directory.
        mkdir $HOME/src/cannonserver
        cd $HOME/src/cannonserver
        cp -r <qtextended-source-directory>/examples/ipc/cannonserver/* .
        chmod +w *
  2. Build the new application.
        export QPEDIR=<qtextended-build-directory>
        $QPEDIR/bin/qbuild
        $QPEDIR/bin/qbuild image
  3. Run Qt Extended.
        $QPEDIR/bin/runqtopia
  4. Run the cannonserver application, you can then run the cannonclient application.

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 94
  2. Apercevoir la troisième dimension ou l'utilisation multithreadée d'OpenGL dans Qt, un article des Qt Quarterly traduit par Guillaume Belz 0
  3. Les développeurs ignorent-ils trop les failles découvertes dans leur code ? Prenez-vous en compte les remarques des autres ? 17
  4. Pourquoi les programmeurs sont-ils moins payés que les gestionnaires de programmes ? Manquent-ils de pouvoir de négociation ? 42
  5. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
  6. Adieu qmake, bienvenue qbs : Qt Building Suite, un outil déclaratif et extensible pour la compilation de projets Qt 17
  7. 2017 : un quinquennat pour une nouvelle version du C++ ? Possible, selon Herb Sutter 6
Page suivante

Le Qt Labs au hasard

Logo

Le moteur de rendu OpenGL

Les Qt Labs sont les laboratoires des développeurs de Qt, où ils peuvent partager des impressions sur le framework, son utilisation, ce que pourrait être son futur. 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 qtextended4.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