It's one possibility to listen for a localeChange, yes. That has the advantage that it will catch the change no matter where it came from.
But since language changes don't happen automatically I usually emit the signal after setting the new QTranslator myself. This has the advantage that I can switch the locale temporarily without all strings switching. I use temporary locales when writing config files with floats, for example. Cheers, Bo. Den 01-10-2013 11:36, Ramakanthreddy Kesireddy skrev: > Hi, > > Thanks for your mail. > > When the language changes, have the LocaleUpdater emit the > localeChanged() signal. Does it mean we need to implement the event() > function in LocaleUpdater > to catch the QEvent::Localechange event and emit localeChanged() signal? > > Best Regards, > Ramakanth > > -----Original Message----- > From: > interest-bounces+ramakanthreddy_kesireddy=mahindrasatyam....@qt-project.org > [mailto:interest-bounces+ramakanthreddy_kesireddy=mahindrasatyam....@qt-project.org] > On Behalf Of Bo Thorsen > Sent: 01 October 2013 13:19 > To: interest@qt-project.org > Subject: Re: [Interest] Dynamic translation using Qt Quick 2.x in Qt5.1.1 > > Den 01-10-2013 07:36, Ramakanthreddy Kesireddy skrev: >> Hi, >> >> I would like to know if it is possible to update the text dynamically >> >> for any locale change in QtQuick(QML) using Qt5.1.1. > > No, not directly. But there are a couple of things you can do instead. > > The key in both my solutions is to have a single C++ object with a property > registered to QML: > > class LocaleUpdater : public QObject { > Q_OBJECT > Q_PROPERTY(QString localeChange READ localeChange > NOTIFY localeChanged) > ... > QString localeChange() const { return QString(); } > }; > > Export this to the QML: > > LocaleUpdater updater; > qml.rootContext()->setContextProperty("localeUpdater", &updater); > > When the language changes, have the LocaleUpdater emit the > localeChanged() signal. You can now do one of two things: > > 1) Use the text updater string directly: > > someObject.text: qsTr("Foo") + localeUpdater.localeChange > > 2) Catch the emitted signal and set all strings > > Connections { > target: localeUpdater > onLocaleChange: { > someObject.text = qsTr("Foo") > } > } > > I hope this helps. > > Bo. > > -- > Bo Thorsen, European Qt Manager, ICS > Integrated Computer Solutions. Delivering World-Class Applications > http://ics.com/services _______________________________________________ > Interest mailing list > Interest@qt-project.org > http://lists.qt-project.org/mailman/listinfo/interest > > ________________________________ > > DISCLAIMER: > This email (including any attachments) is intended for the sole use of the > intended recipient/s and may contain material that is CONFIDENTIAL AND > PRIVATE COMPANY INFORMATION. Any review or reliance by others or copying or > distribution or forwarding of any or all of the contents in this message is > STRICTLY PROHIBITED. If you are not the intended recipient, please contact > the sender by email and delete all copies; your cooperation in this regard is > appreciated. > -- Bo Thorsen, European Qt Manager, ICS Integrated Computer Solutions. Delivering World-Class Applications http://ics.com/services _______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest