Home · All Namespaces · All Classes · Grouped Classes · Modules · Functions codeless banner

Tutorial: Qt Extended IPC Client

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 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 <QtExtended-source-directory>/examples/ipc/cannonclient/* .
        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 will then need to run the cannonclient application.


Copyright © 2009 Trolltech Trademarks
Qt Extended 4.4.3