FORMS += \
mainwindow.ui \
mydialog.ui
TRANSLATIONS += lala_zh.ts\
lala_en.ts
DESTDIR = $$PWD/out
win32 {
COPY_SRC = $$replace(PWD, /, \\)
COPY_DEST = $$replace(DESTDIR, /, \\)
QMAKE_POST_LINK += copy /Y $$COPY_SRC\\*.qm $$COPY_DEST\\*.qm;
}
unix {
}
#install_it.path = $$DESTDIR
#install_it.files = lala_zh.qm
#INSTALLS += \
# install_it
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
m = nullptr;
isChinese = false;
connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(showMy()));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::showMy()
{
//if(m == nullptr)
MyDialog* mr = new MyDialog(this);
mr->show();
}
void MainWindow::setLang(bool isChinese)
{
ui->retranslateUi(this);
}
#include <QTranslator>
#include <mainwindow.h>
MyDialog::MyDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::MyDialog)
{
ui->setupUi(this);
isChinese = false;
connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(showMy()));
connect(this, SIGNAL(setl(bool)), parent, SLOT(setLang(bool)));
}
MyDialog::~MyDialog()
{
delete ui;
}
void MyDialog::showMy()
{
isChinese = !isChinese;
QTranslator trans;
if(isChinese)
{
if(trans.load(qApp->applicationDirPath()+"/lala_zh.qm"))
qApp->installTranslator(&trans);
}
else
{
if(trans.load(qApp->applicationDirPath()+"/lala_en.qm"))
qApp->installTranslator(&trans);
}
ui->retranslateUi(this);
emit setl(isChinese);
}