Fix crash in change language box.

Each time a radiobutton was triggered it was destroyed in refresh().
This commit is contained in:
John Preston 2017-07-18 20:09:48 +03:00
parent a5e0b19b79
commit 10906e2e16
1 changed files with 4 additions and 2 deletions

View File

@ -54,6 +54,7 @@ LanguageBox::Inner::Inner(QWidget *parent, gsl::not_null<Languages*> languages)
_group->setChangedCallback([this](int value) { languageChanged(value); }); _group->setChangedCallback([this](int value) { languageChanged(value); });
subscribe(Lang::Current().updated(), [this] { subscribe(Lang::Current().updated(), [this] {
activateCurrent(); activateCurrent();
refresh();
}); });
} }
@ -96,12 +97,13 @@ void LanguageBox::Inner::languageChanged(int languageIndex) {
void LanguageBox::Inner::activateCurrent() { void LanguageBox::Inner::activateCurrent() {
auto currentId = Lang::Current().id(); auto currentId = Lang::Current().id();
for (auto i = 0, count = _languages->size(); i != count; ++i) { for (auto i = 0, count = _languages->size(); i != count; ++i) {
if ((*_languages)[i].id == currentId) { auto languageId = (*_languages)[i].id;
auto isCurrent = (languageId == currentId) || (languageId == Lang::DefaultLanguageId() && currentId.isEmpty());
if (isCurrent) {
_group->setValue(i); _group->setValue(i);
return; return;
} }
} }
refresh();
} }
void LanguageBox::prepare() { void LanguageBox::prepare() {