View Full Version : how to make translatable items in QComboBox?

11th August 2012, 16:53

As the thread title suggests, I need to make the items translatable in QComboBox. I read item values using Windows API like;

_ui.comboBoxPlayback->addItem(deviceName, i);

The device name here read directly from Windows.

Any ideas?

11th August 2012, 17:10
You can translate only "contsant" strings.

11th August 2012, 17:12
Can the list of possible values for deviceName be determined at compile time?

If yes, then you can provide your own translations using Qt's i18n/l10n support: just put all the strings wrapped with e.g. QT_TR_NOOP in your source file. The strings will be picked up by lupdate and you can provide translations for them. You can then modify your line to use a translation of the string, e.g. _ui.comboBoxPlayback->addItem(tr(deviceName), i).

If not, then surely Qt cannot help you come up with translations at runtime. The Windows API may offer a way to obtain localized device names.