Results 1 to 3 of 3

Thread: language translation with connect signal

  1. #1
    Join Date
    Aug 2014
    Posts
    22
    Thanks
    5
    Qt products
    Qt5

    Default language translation with connect signal

    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.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: language translation with connect signal

    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.

  3. #3
    Join Date
    Aug 2014
    Posts
    22
    Thanks
    5
    Qt products
    Qt5

    Default Re: language translation with connect signal

    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
    Last edited by SSqt5.2; 8th August 2014 at 07:59.

Similar Threads

  1. Language Translation in QT 5.2
    By Vishal@05 in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 3rd March 2014, 14:56
  2. language translation using variable
    By rashmi in forum Qt Programming
    Replies: 0
    Last Post: 15th March 2011, 08:44
  3. Multi language translation
    By bhaskar in forum Installation and Deployment
    Replies: 1
    Last Post: 14th June 2010, 16:30
  4. Replies: 4
    Last Post: 6th February 2009, 11:21
  5. language translation
    By thomasjoy in forum Qt Programming
    Replies: 2
    Last Post: 11th May 2007, 09:25

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.