Qt Linguist translation error
-
@ivanicy It's not that complicated. Basically you need to write custom slot for every class that has a form. Slot is rather simple:
void MainWindow::changeEvent(QEvent *e) { QMainWindow::changeEvent(e); switch (e->type()) { case QEvent::LanguageChange: ui->retranslateUi(this); break; default: break; } }
This is the example for a main program window (hence
MainWindow
andQMainWindow
), but for classes that origin in, let's say, QDialog you'd obviously need to change code a bit. -
@artwaw I have a stack overflow error in this function:
Do you know what is happening here?
Thank you very much!
-
@ivanicy I would change your last line from
MainWindow::changeEvent(...)
to
QMainWindow::changeEvent(...)therefore, making it nor a recursive function but rather a call to the base class.
-
@artwaw I have a stack overflow error in this function:
Do you know what is happening here?
Thank you very much!
-
@J-Hilk I use this function in more windows. I have to use QMainWindow in this windows too?
@ivanicy said in Qt Linguist translation error:
I use this function in more windows. I have to use QMainWindow in this windows too?
First thing in the changeEvent is to call respective ancestor's changeEvent.
EDIT: I use QMainWindow in the example since I stated that it is for QMainWindow descendant. If your window inherits from QDialog you should call QDialog, etc...
-
@ivanicy Please look again at my example - let the QMainWindow try to handle the event first.
In your code you call QMainWindow at the last line of the method. -
@ivanicy said in Qt Linguist translation error:
I use this function in more windows. I have to use QMainWindow in this windows too?
First thing in the changeEvent is to call respective ancestor's changeEvent.
EDIT: I use QMainWindow in the example since I stated that it is for QMainWindow descendant. If your window inherits from QDialog you should call QDialog, etc...
-
Sorry for bothering so much. I have detected that this method don't translate texts that I have put by coding, for example context menus or treeviews.
I use
ui->retranslateUi(this);
Is there something missing to translate the code part as well?
Thank you and sorry guys :(
-
@ivanicy said in Qt Linguist translation error:
ui->retranslateUi(this);
As you can see, only the stuff in the ui struct can be translated with this call - how should this translate e.g. text from a model or somewhere else? The rest has to be done manually.
-
Sorry for bothering so much. I have detected that this method don't translate texts that I have put by coding, for example context menus or treeviews.
I use
ui->retranslateUi(this);
Is there something missing to translate the code part as well?
Thank you and sorry guys :(
@ivanicy said in Qt Linguist translation error:
Sorry for bothering so much. I have detected that this method don't translate texts that I have put by coding, for example context menus or treeviews.
I use
ui->retranslateUi(this);
Is there something missing to translate the code part as well?
Thank you and sorry guys :(
@J-Hilk said in Qt Linguist translation error:
However, if you yourself set a - for translation marked -string inside your application (tr("")), you will have to set that string again after the translator is loaded and installed
-
Sorry for bothering so much. I have detected that this method don't translate texts that I have put by coding, for example context menus or treeviews.
I use
ui->retranslateUi(this);
Is there something missing to translate the code part as well?
Thank you and sorry guys :(
@ivanicy A way to avoid this is to update menu strings each time the context menu is displayed (there is a handy signal to connect to - QMenu::aboutToShow() - this way you can use tr().
As for treeviews, it really depends on how you obtain the data, from and when. Headers, I believe (never tried) could be automated. As for other kind of data, it really depends but can be difficult.