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>
10 #include <qpushbutton.h>
14 #include <qtextcodec.h>
16 /* Get getpid() declaration. */
22 main (int argc
, char *argv
[])
26 QApplication
application (argc
, argv
);
28 GettextTranslator
*translator
=
29 new GettextTranslator (&application
, "hello-c++-qt", LOCALEDIR
);
31 QTranslator
*translator
= new QTranslator (NULL
);
32 translator
->load (QString ("hello-c++-qt") + "_" + QTextCodec::locale(),
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
);
49 // NOT using QString::sprintf because it doesn't support reordering of
51 //label2text.sprintf (_("This program is running as process number %d"),
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.
71 // Start the event loop.
73 return application
.exec ();