#include <QtGui>//-----------------------------------------------------------------class MainWindow : public QMainWindow { Q_OBJECTpublic: MainWindow();private slots: void triggeredRussian(); void triggeredEnglish();private: void createActions(); void createMenus(); void retranslateUi(); QPushButton *buttonCalculate; QMenu *languageMenu; QAction *russianAct; QAction *englishAct; QTranslator *translator;};//----------------------------------------------------------------MainWindow::MainWindow(){ buttonCalculate = new QPushButton(tr("Calculate")); setCentralWidget(buttonCalculate); createActions(); createMenus(); translator = new QTranslator;}void MainWindow::createActions(){ russianAct = new QAction(tr("Russian"), this); russianAct->setCheckable(true); russianAct->setChecked(false); englishAct = new QAction(tr("English"), this); englishAct->setCheckable(true); englishAct->setChecked(true); connect(russianAct, SIGNAL(triggered()), this, SLOT(triggeredRussian())); connect(englishAct, SIGNAL(triggered()), this, SLOT(triggeredEnglish()));}void MainWindow::createMenus(){ languageMenu = menuBar()->addMenu(tr("Language")); languageMenu->addAction(russianAct); languageMenu->addAction(englishAct);}void MainWindow::triggeredRussian() { russianAct->setChecked(true); englishAct->setChecked(false); translator->load("eng_to_rus.qm","."); qApp->installTranslator(translator); retranslateUi();}void MainWindow::triggeredEnglish() { russianAct->setChecked(false); englishAct->setChecked(true); qApp->removeTranslator(translator); retranslateUi();}void MainWindow::retranslateUi() { languageMenu->setTitle(tr("Language")); russianAct->setText(tr("Russian")); englishAct->setText(tr("English")); buttonCalculate->setText(tr("Calculate"));}int main(int argc, char *argv[]){ QApplication app(argc, argv); MainWindow mw; mw.show(); return app.exec();}#include "main.moc"
<?xml version="1.0" encoding="utf-8"?><!DOCTYPE TS><TS version="1.1" language="ru_RU"><defaultcodec></defaultcodec><context> <name>MainWindow</name> <message> <location filename="main.cpp" line="60"/> <source>Calculate</source> <translation type="unfinished">Вычислить</translation> </message> <message> <location filename="main.cpp" line="58"/> <source>Russian</source> <translation type="unfinished">Русский</translation> </message> <message> <location filename="main.cpp" line="59"/> <source>English</source> <translation type="unfinished">Английский</translation> </message> <message> <location filename="main.cpp" line="57"/> <source>Language</source> <translation type="unfinished">Язык</translation> </message></context></TS>
void MainWindow::triggeredEnglish(){ QTranslator* translator = new QTranslator; m_rus = false; //qDebug() << m_rus; kn_rus->setChecked(false); translator->load("C:/Pr1/pr1_en.qm","."); // QUiLoader::setLanguageChangeEnabled(true); qDebug() << translator->load("C:/Pr1/pr1_en.qm","."); qApp->installTranslator(translator);}
C++ (Qt)bool MainWindow::event( QEvent * e ){ if ( e->type() == QEvent::LanguageChange ) { retranslateUi( this ); return true; } return QMainWindow::event( e );}
void MainWindow::triggeredEnglish(){ QTranslator* translator = new QTranslator; m_rus = false; kn_rus->setChecked(false); translator->load("C:/Pr1/pr1_en.qm","."); qDebug() << translator->load("C:/Pr1/pr1_en.qm","."); qApp->installTranslator(translator);}bool MainWindow::event(QEvent* e){ if (e->type() == QEvent::LanguageChange) { retranslateUi(this); return true; } return QMainWindow::event(e);}
no 'bool MainWindow::event(QEvent*)' member function declared in class 'MainWindow'
C++ (Qt)bool event( QEvent * e );
QTextCodec::setCodecForTr(QTextCodec::codecForName("Windows-1251"));textEdit->setText(tr("Введенное количество секунд ")+QString::number(iS) + tr(" соответствует ") + QString::number(oH) + tr(" часам, " ) + QString::number(oM) + tr(" минутам, ") + QString::number(oS) + tr(" секундам"));
void MainWindow::triggeredRussian(){ QTranslator* translator = new QTranslator; m_rus = true; qDebug() << m_rus; kn_eng->setChecked(false); translator->load("./pr1_ru.qm","."); qDebug() << translator->load("./pr1_ru.qm","."); qApp->installTranslator(translator);}void MainWindow::triggeredEnglish(){ QTranslator* translator = new QTranslator; m_rus = false; kn_rus->setChecked(false); translator->load("./pr1_en.qm","."); qDebug() << translator->load("./pr1_en.qm","."); qApp->installTranslator(translator);}bool MainWindow::event(QEvent* e){ if (e->type() == QEvent::LanguageChange) { retranslateUi(this); return true; } return QMainWindow::event(e);}
#include <QtGui>#include "proga1_about.h"MyAbout::MyAbout(QWidget *parent) : QWidget(parent){ setupUi(this); connect(pushButton, SIGNAL(pressed()), this, SLOT(close()));}bool MyAbout::event(QEvent* e){ if (e->type() == QEvent::LanguageChange) { retranslateUi(this); return true; } return QWidget::event(e);}