No empty .Rs/.Re
[netbsd-mini2440.git] / gnu / dist / gettext / gettext-tools / examples / hello-c++-qt / hello.cc
blob0932314d112a4d1c7092a6b502787c38a6031c6f
1 // Example for use of GNU gettext.
2 // Copyright (C) 2003 Free Software Foundation, Inc.
3 // This file is in the public domain.
5 // Source code of the C++ program.
7 #include <qapplication.h>
8 #include <qmainwindow.h>
9 #include <qlabel.h>
10 #include <qpushbutton.h>
11 #include <qstring.h>
12 #include <qvbox.h>
13 #include <qhbox.h>
14 #include <qtextcodec.h>
16 /* Get getpid() declaration. */
17 #if HAVE_UNISTD_H
18 # include <unistd.h>
19 #endif
21 int
22 main (int argc, char *argv[])
24 // Initializations.
26 QApplication application (argc, argv);
27 #if 0
28 GettextTranslator *translator =
29 new GettextTranslator (&application, "hello-c++-qt", LOCALEDIR);
30 #else
31 QTranslator *translator = new QTranslator (NULL);
32 translator->load (QString ("hello-c++-qt") + "_" + QTextCodec::locale(),
33 PKGLOCALEDIR);
34 #endif
35 application.installTranslator (translator);
36 #define _(string) application.translate ("", string)
38 // Create the GUI elements.
40 QMainWindow *window = new QMainWindow ();
41 window->setCaption ("Hello example");
43 QVBox *panel = new QVBox (window);
44 panel->setSpacing (2);
46 QLabel *label1 = new QLabel (_("Hello, world!"), panel);
48 QString label2text;
49 // NOT using QString::sprintf because it doesn't support reordering of
50 // arguments.
51 //label2text.sprintf (_("This program is running as process number %d"),
52 // getpid ());
53 label2text = _("This program is running as process number %1.").arg(getpid ());
54 QLabel *label2 = new QLabel (label2text, panel);
56 QHBox *buttonbar = new QHBox (panel);
57 QWidget *filler = new QWidget (buttonbar); // makes the button right-aligned
58 QPushButton *button = new QPushButton ("OK", buttonbar);
59 button->setMaximumWidth (button->sizeHint().width() + 20);
60 QObject::connect (button, SIGNAL (clicked ()), &application, SLOT (quit ()));
62 panel->resize (panel->sizeHint ());
63 window->resize (panel->frameSize ());
65 application.setMainWidget (window);
67 // Make the GUI elements visible.
69 window->show ();
71 // Start the event loop.
73 return application.exec ();