Merge pull request #2222 from jwillemsen/jwi-dllexportwarning
[ACE_TAO.git] / TAO / tests / QtTests / client.cpp
blob09d3f4f91ef992bd135ff2066450067a18dd4ac1
1 #include "testC.h"
2 #include "ace/Get_Opt.h"
3 #include "ace/Argv_Type_Converter.h"
4 #include "tao/QtResource/QtResource_Loader.h"
6 #include "client.h"
8 int
9 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
11 ACE_Argv_Type_Converter ct (argc, argv);
12 QApplication app (argc, ct.get_ASCII_argv ());
13 TAO::QtResource_Loader qt_resources (&app);
15 try
17 CORBA::ORB_var orb =
18 CORBA::ORB_init (argc, argv);
20 Client client (orb.in (), app);
22 client.parse_args (argc, argv);
24 // Creates the Qt widgets
25 client.create_widgets ();
27 // This may look a bit suspect, but Qt wants the manager widget
28 // as the toplevel widget unlike Xt for display purposes.
29 app.setActiveWindow (&(client.mainwindow_));
31 // Show them on Screen
32 client.show ();
34 app.exec ();
36 catch (const CORBA::Exception& ex)
38 ex._tao_print_exception ("Caught exception:");
39 return 1;
41 return 0;
44 Client::Client (CORBA::ORB_ptr orb,
45 QApplication &qapp)
46 : orb_ (CORBA::ORB::_duplicate (orb)),
47 qapp_ (&qapp)
51 Client::~Client ()
53 delete this->slider_;
54 delete this->push_button_;
57 void
58 Client::parse_args (int argc,
59 ACE_TCHAR *argv[])
61 const ACE_TCHAR *ior = ACE_TEXT("file://test.ior");
63 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:"));
64 int c;
66 while ((c = get_opts ()) != -1)
67 switch (c)
69 case 'k':
70 ior = get_opts.opt_arg ();
71 break;
72 case '?':
73 default:
74 ACE_ERROR ((LM_ERROR,
75 "usage: %s "
76 "-k <ior> "
77 "\n",
78 argv [0]));
81 CORBA::Object_var object =
82 this->orb_->string_to_object (ior);
84 this->server_ =
85 LCD_Display::_narrow (object.in ());
87 if (CORBA::is_nil(this->server_.in ()))
89 ACE_DEBUG ((LM_DEBUG,
90 "\n The server value is nil "));
94 void
95 Client::create_widgets (/**/)
97 // Ewsize the box
98 this->mainwindow_.resize (200,120);
99 this->mainwindow_.setWindowTitle("QtClient");
101 // Make a pushbutton widget
102 ACE_NEW (this->push_button_,
103 QPushButton ("Quit"));
104 box_.addWidget(this->push_button_);
106 // Connect the click () SIGNAL routine with the SLOT handler that we
107 // have defined
108 QObject::connect (this->push_button_,
109 SIGNAL (clicked()),
110 this,
111 SLOT (shutdown_call ()));
113 // Create a slider widget
114 ACE_NEW (this->slider_,
115 QSlider (Qt::Horizontal));
117 // Add resource for the slider
118 this->slider_->setRange (0, 99);
119 this->slider_->setValue (0);
121 box_.addWidget(this->slider_);
124 // Connect the valuechanged SIGNAL routine with the slot that we
125 // have defined. THe slot routine would invoke the remote call.
126 QObject::connect (this->slider_,
127 SIGNAL (valueChanged (int)),
128 this,
129 SLOT (remote_call (int)));
131 this->mainwindow_.setLayout(&box_);
135 void
136 Client::show ()
138 this->mainwindow_.show ();
141 void
142 Client::remote_call (int val)
144 this->server_->send_val (val);
147 void
148 Client::shutdown_call ()
150 this->server_->shutdown ();