[Qt-interest] Handling translations in a multi-threaded server
Tony Rietwyk
tony.rietwyk at rightsoft.com.au
Thu May 19 14:03:30 CEST 2011
> -----Original Message-----
> Sent: Thursday, 19 May 2011 20:42 PM
>
> On Thu, May 19, 2011 10:35, Tony Rietwyk wrote:
> > I have multi-threaded servers that handle database queries from
> > potentially many clients in many different countries (especially the
> > European server). The requests are processed via a thread
> pool. Each
> > request has the locale code for the translation file to be
> used by the
> > IBase sql driver.
> >
> > The problem is that the IBase driver calls
> QApplication::translate for
> > errors. This implies all threads have to use the same
> translation file.
> >
> > How have others worked around this limitation?
>
> I haven't done this yet, but I would pre-load QTranslator
> objects for all
> languages, NOT install them in the QApplication object, and then call
> QTranslator::translate with the untranslated string from the
> IBase driver.
>
> I hope this wasn't too confusing...
>
>
> Konrad
Hi Konrad,
Not at all. I was coming to the same conclusion myself - load them all in a
QHash<QString, QTranslator *>. Luckily, the QTranslator::translate method
is const, so multi-threaded access should not require locking. Since
nothing gets installed on the application, the English messages will stay
the same when the IBase driver does its translate.
Thanks!
Tony
More information about the Qt-interest-old
mailing list