PDA

View Full Version : language translation with connect signal



SSqt5.2
6th August 2014, 12:15
Hi,

I am using two combo-boxes for language selection.
First combo-box selects the language and 2nd displays various messages in the selected language.
How should i connect the two combo-boxes with signals and Slot?
or is there any other method to do this?

Thanks in advance.

ChrisW67
6th August 2014, 21:32
Connect the currentIndexChanged() signal of the first combo to a custom slot that loads the second combo with the strings matching the language selected.

You could use a QTranslator in that slot to look up string translations using Qt's i18n features.

SSqt5.2
8th August 2014, 06:05
Hi Chris,
thanks for reply.
I am proceeding in same way.
I have created a custom slot for the derived class with the example mentioned in QT doc for Pushbutton.
My Derived class has a combobox(with required strings) and QTranslator.
i have achived the functionality till getting the index of 1st combobox and assign the same index to 2nd (derived) combobox with custom slot.
the next part for language conversion or loading the QM file with that index is not working.



class Defined is

class QTranslator;
class QComboBox;
class myclass : public QWidget
{
Q_OBJECT
public:
explicit myclass(QWidget *parent);
QComboBox *langstring;
QTranslator *langTrans;
private slots:
void slotCustomLangChange(int index);
};



class constructor is
{
langstring = new QComboBox(this->parentWidget());
langstring->addItem(QObject::tr("Good Morning"));
langstring->addItem(QObject::tr("Thank you"));
langstring->addItem(QObject::tr("What is your Name?"));

langTrans = new QTranslator(this->parentWidget());
}


in slot function i am doing
{
langstring->setCurrentIndex(index); //dummy for check
if(index == Japanese)
{
langTrans->load("D:/Qt_S_Projects/Qt_1/Translations/Tr1_jp.qm");
}
else if(index == French)
{
langTrans->load("D:/Qt_S_Projects/Qt_1/Translations/Tr1_fr.qm");
}
}

in main i am doing this.
//////////////
myclass *mydevclass = new myclass (&window);
mydevclass->show();

QObject::connect(LangSel, SIGNAL(currentIndexChanged(int)),
mydevclass, SLOT(slotCustomLangChange(int)));

app.installTranslator(mydevclass->langTrans);

///////////////////

Can you guess any issues? any suggestion?


thanks