[Qt-interest] Handling translations in a multi-threaded server
Scott Aron Bloom
Scott.Bloom at onshorecs.com
Thu May 19 16:49:03 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
============================
Will each thread connection use one translator.. or will it change on
each request?
If its each request, I would make your hash a bit bigger.. and have a
Thread->name of translation->translator * lookup...
And have a translator avaialbe for (eventually) for each thread so you
don't have cross thread dependencies
Scott
More information about the Qt-interest-old
mailing list