Home · All Classes · Grouped Classes · Annotated · Functions

Tutorial: Qtopia IPC Client

Files:

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

The cannonclient application issues a shoot order request to any listening cannonserver applications, and once it receives a result broadcast, exits.

CannonResultListener Class Definition

    class CannonResultListener : public QObject
    {
        Q_OBJECT

    public:
        CannonResultListener(QObject *parent = 0);

    public slots:
        void missed();
        void hit();
    };

The CannonResultListener class is a QObject with two slots. These slots simply print a message depending on the slot being called and destroy the CannonResultListener by calling deleteLater(). This will cause the application to exit.

CannonResultListener Class Implementation

The missed() slot is called whenever a message of the same type arrives on the IPC channel. This slot prints a message and destroys the listener.

    void CannonResultListener::missed()
    {
        qDebug() << "Cannon missed.";
        deleteLater();
    }

The hit() slot is similar.

    void CannonResultListener::hit()
    {
        qDebug() << "Cannon HIT!!!";
        deleteLater();
    }

The interesting bit is in the main function. First we create a new CannonResultListener:

        CannonResultListener *listener = new CannonResultListener;

We then create a new QtopiaIpcAdaptor that will operate on the QPE/CannonExample channel.

        QtopiaIpcAdaptor *adaptor = new QtopiaIpcAdaptor("QPE/CannonExample");

Next we connect the two messages that we can get back from the Cannon Server application to the slots defined in the CannonResultListener.

        QtopiaIpcAdaptor::connect(adaptor, MESSAGE(missed()), listener, SLOT(missed()));
        QtopiaIpcAdaptor::connect(adaptor, MESSAGE(hit()), listener, SLOT(hit()));

Building the Cannon Client application.

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

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


Copyright © 2008 Nokia Trademarks
Qtopia 4.3.3