Home > Back-end >  QT Model view with translation
QT Model view with translation

Time:02-16

I am using QT and lately got into translations using tr() function.

Is it possible to work with model/view architecture and translations with QT? By that I mean real-time translation of model data - let's say I have a data like that:

n age    ready
1 old    yes
2 young  no
3 old    yes
4 young  yes
5 old    yes
6 old    yes
7 medium no
8 medium no
9 medium no

And I would like to define a translation for these fixed values in real-time when it gets out of database. (e.g.

yes - tak
no - nie
...

I have tried to tr() values after getting them from database, but I cannot use QString at tr()

CodePudding user response:

tr() requires const char * so all you need to do is to convert your QString to const char *. Read this QString to char* conversion

You can use for example tr(yourstring.toUtf8().constData()).

  • Related