runtime - qt QTranslator reuse -


I have found that QT documentation is not very important on some aspects of translation. I am trying to understand their behavior with the use of testing. Error. The final goal is to make changes to the translation on runtime, but I am very confused about the extent to which the curtustoliter object can be reused.

Consider this (where 'A' is the main example of the application):

  QTranslator translator; Translator.load ("mytranslation_cz"); An.installTranslation (& amp; Translator); (...) a.removeTranslation (and translator)   

Now the translator was removed from the application, but what happened to the translator object?

In my tests when it was done again after the next code

  translator.load ("mytranslation_fr"); An.installTranslation (& amp; Translator);   

This did nothing in the main () and crashes the app when it calls from widgets (using the main app from the pointer).

That's why I doubt that I will need to create a translation per controllers object, which I want to load in the application and I can not reuse the Curatorialiter object Am I right in this assumption?

And aside from the QTranslator object being executed as a question (), is it possible to reinstall it later?

  QTranslator Translator; Q translator translator 1; Translator.load ("mytranslation_cz"); Translator1.load ("mytranslation_fr"); An.installTranslation (& amp; Translator); (...) a.removeTranslation (and translator); An.installTranslation (& translator1); (...) a.removeTranslation (and Translator 1); An.installTranslation (& trasnlator); //it will work? Thanks for any explanation because I'm confused to some extent what happens to Qurrenession objects when translations are removed from the application and removed  especially if the cutracements Can the object be reused for multiple translation in some way over runtime?  

can basically be considered as a function in a simple meaning that opens up any given code .qm file, reads all translated values ​​and loads it for a specific language.

Now in the normal operation, you do not want to reuse it as many languages, "re-use" (even if you have permission) by using your UI language for every language given to each language < Code> .qm , which is just basically an upper part that you do not need.

Your perception of creating a QTranslator for each language is correct for your side question, yes, you can also reuse it. Individual QTranslator objects get the benefit of each translation. Just call with the current translation and then qApp-> gt; Installtranslator () This is the way you are reusing reliable translations and when you are please.

The way we create it is to add the subclassing QApplication and 2 functions

  Zero Applications :: Create Transcents () / Translator_a a QMap & lt; QString, QTranslator * & gt; If (! Translator_recognition ()) return; QStringList languages; Languages ​​& lt; & Lt; "N" & lt; & Lt; "AR" & lt; & Lt; "Zh"; Foreign Language (Caststring Language, Language) {Q translator * translator = new Q translator (example ()); Translator- & gt; Load (language); Translators_.insert (language, translator); }}   

Now this function is called at the beginning of the application.

The second function is similar to the following:

  void application :: Switch language (QString language) {// current_translator_ is a qtranslator * if (current_translator_) remove the translator ( Current_translator_); Current_translator_ = translator_real (language, nullptr); If (current_translator_) installed translator (current_translator_); }   

That's it. Using the second function, you can switch your language from time to time as you please.

Some things that you are changing from time to time on QTranslator are automatically translated as all the translations from your .ui file strings Has been marked, although the code will not be set up. You need to override and then check to see if the type of event type is QEvent :: LanguageChange and then set the required string for that code according to the code which is not forgotten < Code> tr () while doing this)

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -