EXAMPLE 1:
#include <QApplication>
#include <QLabel>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QLabel *label = new QLabel("Hello Qt!");
// Widgets are always created hidden so that we can customize them before showing them, thereby avoiding flicker.
label->show();
return app.exec();
}
EXAMPLE 2:
#include <QApplication>
#include <QLabel>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QLabel *label = new QLabel;
label->setText( "Hello Qt!" );
label->show();
return app.exec();
}
EXAMPLE 3:
#include <QApplication>
#include <QLabel>
#include <QTextCodec>
int main( int argc, char *argv[] )
{
QApplication app( argc, argv);
QTextCodec::setCodecForTr( QTextCodec::codecForName( "utf-8" ) );
QLabel *label = new QLabel( QObject::tr("同一个世界,同一个梦想") );
label->show();
return app.exec();
}
Example 4:
#include <QApplication>
#include <QLabel>
int main( int argc, char *argv[] )
{
QApplication app( argc, argv );
QLabel *label = new QLabel( "<h2>Hello <font color = red>World</font><h2>" );
label->show();
return app.exec();
}