Home · All Namespaces · All Classes · Grouped Classes · Modules · Functions |
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.
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.
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()));
To install and run the Cannon Client application, carry out the following steps.
mkdir $HOME/src/cannonclient cd $HOME/src/cannonclient cp -r <QtExtended-source-directory>/examples/ipc/cannonclient/* . chmod +w *
export QPEDIR=<QtExtended-build-directory> $QPEDIR/bin/qbuild $QPEDIR/bin/qbuild image
$QPEDIR/bin/runqtopia
Copyright © 2009 Trolltech | Trademarks | Qt Extended 4.4.3 |