对于新版的Qt Creator要采用一下方式建工程:
1,
然后采用默认的往下执行。
2,建立ui文件:
3,新建一个main.cpp
#include <QApplication>
#include <QTranslator>
#include <QProcess>
#include <QLocale>
#include <QLibraryInfo>
#include <QDebug>
#include <QtGui/QtGui>
#include"form.h"
int main(int argc,char* argv[])
{
QApplication app(argc, argv);
QTextCodec::setCodecForTr(QTextCodec::codecForName("gb18030"));
Form mydialog;
QMessageBox box;
QTranslator translator;
{
QStringList environment = QProcess::systemEnvironment();
QString str;
bool bFinded =false;
foreach(str,environment)
{
if(str.startsWith("QTDIR="))
{
bFinded =true;
break;
}
}
if(bFinded)
{
str=str.mid(6);
bFinded =translator.load("qt_"+QLocale::system().name(),
str.append("/translations"));
if(bFinded)
qApp->installTranslator(&translator);
else
{
// qDebug() << QObject::trUtf8("没有中文");
box.setWindowTitle("warning");
box.setIcon(QMessageBox::Warning);
box.setText("没有支持中文的国际化翻译软件!!");
box.setStandardButtons(QMessageBox::Yes);
box.exec();
}
}
else
{
//qDebug() << QObject::trUtf8("必须设置");
box.setWindowTitle("warning");
box.setIcon(QMessageBox::Warning);
box.setText("必须设置QTDIR环境变量!!");
box.setStandardButtons(QMessageBox::Yes);
box.exec();
exit(1);
}
}
mydialog.show();
return app.exec();
}
编译运行就是你设计的画面: