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>
9 #include <qpushbutton.h>
13 #include <qtextcodec.h>
15 /* Get getpid() declaration. */
21 main (int argc
, char *argv
[])
25 QApplication
application (argc
, argv
);
27 GettextTranslator
*translator
=
28 new GettextTranslator (&application
, "hello-c++-qt", LOCALEDIR
);
30 QTranslator
*translator
= new QTranslator (NULL
);
31 translator
->load (QString ("hello-c++-qt") + "_" + QTextCodec::locale(),
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
);
48 // NOT using QString::sprintf because it doesn't support reordering of
50 //label2text.sprintf (_("This program is running as process number %d"),
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.
70 // Start the event loop.
72 return application
.exec ();