Nice way to maintain Qt labeling and text in UI

What is the best way / common practice to maintain all the string resources found in the UI in Qt, especially text input / text in combo boxes, etc. (since this is the one that is often used in the code itself)?

I know Android has this information about string resources, so the resources only need to be changed in one position.

Qt has something similar, or do I need to initialize string resources in code, not in the XML interface itself ...

+3


source to share


2 answers


AFAIK, there is no built-in mechanism for string resources in Qt. If you want to maintain strings at build time, you can define them as global variables in a single .h / .cpp file and reuse them in your code.



Otherwise, you can use Qt translator files (binaries) and load them along with your application. If you need to change the string, you just need to edit the translation file (xml) and "recompile" it with the lrelease utility without having to rebuild the application.

+1


source


There is a mechanism for dynamic translation of texts in the application, but it is slightly different from the Android string resources, but achieves the same goals.

Qt uses the i18n system, modeled after the standard known unix gettext

. It works very similarly to iOS NSLocalizedString

if it rings a bell.

http://doc.qt.io/qt-5/qobject.html#tr



This one is also worth reading:

The Android approach is a bit unique and you shouldn't expect it to be “standard everywhere”. It works, that's fine, but it's not the standard way of doing things on the desktop.

0


source







All Articles