• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /netgear-WNDR4500-V1.0.1.40_1.0.68/ap/gpl/timemachine/gettext-0.17/gettext-tools/examples/hello-c++-qt/
1// Example for use of GNU gettext.
2// This file is in the public domain.
3
4// Source code of the C++ program.
5
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>
14
15/* Get getpid() declaration.  */
16#if HAVE_UNISTD_H
17# include <unistd.h>
18#endif
19
20int
21main (int argc, char *argv[])
22{
23  // Initializations.
24
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)
36
37  // Create the GUI elements.
38
39  QMainWindow *window = new QMainWindow ();
40  window->setCaption ("Hello example");
41
42  QVBox *panel = new QVBox (window);
43  panel->setSpacing (2);
44
45  QLabel *label1 = new QLabel (_("Hello, world!"), panel);
46
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);
54
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 ()));
60
61  panel->resize (panel->sizeHint ());
62  window->resize (panel->frameSize ());
63
64  application.setMainWidget (window);
65
66  // Make the GUI elements visible.
67
68  window->show ();
69
70  // Start the event loop.
71
72  return application.exec ();
73}
74