From a312b9bb47a7ff3bcaf2c771e24382a0a9b279cb Mon Sep 17 00:00:00 2001 From: bustico Date: Wed, 27 Jul 2011 14:05:38 +0000 Subject: show how to bind more than one regexp in a Qt inherited class --- testIvyQt.cxx | 47 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/testIvyQt.cxx b/testIvyQt.cxx index 1380982..9eaca76 100644 --- a/testIvyQt.cxx +++ b/testIvyQt.cxx @@ -1,7 +1,7 @@ /* - * Ivy probe + * testIvyQt * - * Copyright (C) 1997-1999 + * Copyright (C) 1997-2010 * Centre d'Études de la Navigation Aérienne * * Main and only file @@ -14,6 +14,23 @@ * copyright notice regarding this software */ + +/* this example show how to bind a regexp with a one message / one class methaphor + using callback on OnMessage method + + it shows also how to bind several regexp in one class using BindMsg method. + it shows a common usage of user_data callback parameter : using it so pass a pointer on object + + usage : + launch test_IvyQt + in another terminal launch ivyprobe '(.*)' + manipulate slider, see effect on ivyprobe + send message in ivyprobe : set col red (or any color) and see effects on test_IvyQt + +*/ + + + #include #include @@ -72,6 +89,8 @@ class MyWidget : public QWidget, public IvyApplicationCallback, public IvyMessag void OnApplicationDecongestion(IvyApplication *app); void OnApplicationFifoFull(IvyApplication *app); void OnMessage(IvyApplication *app, int argc, const char **argv); + static void myOwnCB1 ( IvyApplication *app, void *user_data, int argc, const char **argv ); + static void myOwnCB2 ( IvyApplication *app, void *user_data, int argc, const char **argv ); private: QSlider *slider; @@ -113,14 +132,36 @@ private slots: } +void MyWidget::myOwnCB1 ( IvyApplication *app, void *user_data, int argc, const char **argv ) +{ + printf ("coucou CB1\n"); +} +void MyWidget::myOwnCB2 ( IvyApplication *app, void *user_data, int argc, const char **argv ) +{ + MyWidget *w = static_cast (user_data); + printf ("coucou CB2\n"); + + if (argc >= 1) { + QPushButton *b = w->quit; + QPalette pal = b->palette(); + QColor color (argv[0]); + + pal.setColor( QPalette::Button, color ); + b->setPalette( pal ); + b->setAutoFillBackground( true ); + } else { + printf ("no color given\n"); + } +} void MyWidget::IvyStart() { bus = new Ivy( "TestIvyQt", "TestIvyQt READY", BUS_APPLICATION_CALLBACK( ivyAppConnCb, ivyAppDiscConnCb ),false); - bus->BindMsg( "(\\d+)", this ); + bus->BindMsg( "^coucou", new IvyMessageCallbackFunction(myOwnCB1, NULL)); + bus->BindMsg( "^set col (.*)", new IvyMessageCallbackFunction(myOwnCB2, this)); bus->start(NULL); } -- cgit v1.1