retranslateUi method freezing application - Multi language support
-
I added second language to my program with advices from: https://forum.qt.io/topic/143541/proper-way-for-adding-2nd-language
I have a combobox for language selection. When I change language in combobox, the programs' language changing without problem on my computer.
But when i tried on another computer, the program freezes. I tried debugging but no chance, because program is not crashing, just freezing.
I have this on my settings page:
// t is a QTranslator object void Settings::on_comboBoxLanguage_currentIndexChanged(int index) { if(index == 0){ t.load(":/i18n/lang_en.qm"); db->updateLanguage("English"); } else if(index == 1){ t.load(":/i18n/lang_it.qm"); db->updateLanguage("Italian"); } QCoreApplication::installTranslator(&t); Q_EMIT RetranslateUI(); }
And I have this on other ui classes:
void MainPage::RetranslateUISlot() { ui->retranslateUi(this); }
Both computers are Linux but different distros. I dont know how to debug it. Any idea?
-
@masa4 said in retranslateUi method freezing application - Multi language support:
. I tried debugging but no chance, because program is not crashing, just freezing.
And what was the result - what do you see in the backtrace where your program hangs?
-
@Christian-Ehrlicher When I stop debugging, there is lots of line that dont make much sense to me. But it is like the
RetranslateUI
signal keep emitting continuosly. I dont know -
@masa4 do you retranslate/recreate your combobox model ?
It's possible, that with each retranslate the currentIndex changed signal is emitted. Because this signal is sent whenever the currentIndex in the combobox changes either through user interaction or programmatically.
-
@J-Hilk said in retranslateUi method freezing application - Multi language support:
It's possible, that with each retranslate the currentIndex changed signal is emitted. Because this signal is sent whenever the currentIndex in the combobox changes either through user interaction or programmatically.
That's also my idea and therefore the hint to look at the backtrace but as always I'm getting ignored :)
-
@Christian-Ehrlicher thats normal :D
the strange thing is still that is happens on one pc and not on the other, the behaviour should be the same in both cases, right?
-
@J-Hilk said in retranslateUi method freezing application - Multi language support:
the behaviour should be the same in both cases
Yes, but maybe there is a QueuedConnection somewhere which affects the timing. Need to see the backtrace (or more than one at different times when they really differ)
-
-
@masa4 said in retranslateUi method freezing application - Multi language support:
qt 6.x and other one uses 5.x .
how does that work? Did you compile it for Qt5 and for Qt6. Or do you simply run the Qt5 version with Qt6 libraries and it accidentally worked ?
-
@J-Hilk No i recompiled project on other pc with qt5 libraries. I always do like that without any problem. If i am not wrong the language changing mechanism was working without any issue. But after it, i add several other things to my program and now i got that problem.
For example I added a label to one of my ui's. I didnt create a translation for that label yet. Can it be cause the problem?
Additionally,
I have this in Settings.cpp constructor:if(db->selectLanguage()=="English"){ ui->comboBoxLanguage->setCurrentIndex(0); t.load(":/i18n/lang_en.qm"); } else if(db->selectLanguage()=="Italian"){ ui->comboBoxLanguage->setCurrentIndex(1); t.load(":/i18n/lang_it.qm"); } QCoreApplication::installTranslator(&t); Q_EMIT RetranslateUI();
When program starts, I am creating a settins object in mainwidget so this constructors run and im reading the language from databse and setting the ui language according to db.
-
@masa4 Hi,
There's no need for such a signal:
void MyWidget::changeEvent(QEvent *event) { if (event->type() == QEvent::LanguageChange) { titleLabel->setText(tr("Document Title")); ... okPushButton->setText(tr("&OK")); } else QWidget::changeEvent(event); }
See the internationalization documentation for more.