Install gettext-0.18.1.1.tar.gz
[msysgit.git] / mingw / share / doc / gettext / examples / hello-c++-qt / hello.cc
blob577a54e1b3e6ffc8ec87c0e2862931917111e325
1 // Example for use of GNU gettext.
2 // This file is in the public domain.
4 // Source code of the C++ program.
6 #include <qapplication.h>
7 #include <qmainwindow.h>
8 #include <qlabel.h>
9 #include <qpushbutton.h>
10 #include <qstring.h>
11 #include <qvbox.h>
12 #include <qhbox.h>
13 #include <qtextcodec.h>
15 /* Get getpid() declaration. */
16 #if HAVE_UNISTD_H
17 # include <unistd.h>
18 #endif
20 int
21 main (int argc, char *argv[])
23 // Initializations.
25 QApplication application (argc, argv);
26 #if 0
27 GettextTranslator *translator =
28 new GettextTranslator (&application, "hello-c++-qt", LOCALEDIR);
29 #else
30 QTranslator *translator = new QTranslator (NULL);
31 translator->load (QString ("hello-c++-qt") + "_" + QTextCodec::locale(),
32 PKGLOCALEDIR);
33 #endif
34 application.installTranslator (translator);
35 #define _(string) application.translate ("", string)
37 // Create the GUI elements.
39 QMainWindow *window = new QMainWindow ();
40 window->setCaption ("Hello example");
42 QVBox *panel = new QVBox (window);
43 panel->setSpacing (2);
45 QLabel *label1 = new QLabel (_("Hello, world!"), panel);
47 QString label2text;
48 // NOT using QString::sprintf because it doesn't support reordering of
49 // arguments.
50 //label2text.sprintf (_("This program is running as process number %d"),
51 // getpid ());
52 label2text = _("This program is running as process number %1.").arg(getpid ());
53 QLabel *label2 = new QLabel (label2text, panel);
55 QHBox *buttonbar = new QHBox (panel);
56 QWidget *filler = new QWidget (buttonbar); // makes the button right-aligned
57 QPushButton *button = new QPushButton ("OK", buttonbar);
58 button->setMaximumWidth (button->sizeHint().width() + 20);
59 QObject::connect (button, SIGNAL (clicked ()), &application, SLOT (quit ()));
61 panel->resize (panel->sizeHint ());
62 window->resize (panel->frameSize ());
64 application.setMainWidget (window);
66 // Make the GUI elements visible.
68 window->show ();
70 // Start the event loop.
72 return application.exec ();