Results 1 to 4 of 4

Thread: Qt Multi language QCombobox problem

  1. #1
    Join Date
    Jul 2012
    Posts
    20
    Thanks
    8
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4

    Default Qt Multi language QCombobox problem

    I have got a problem with multi language qt (change language on the fly). My form have a combobox which should be translated when language changed. When languageChanged, the app call method retranslateUi() to translate item in the combobox. The combobox have slot corresponding for signal currentIndexChanged().

    Qt Code:
    1. void on_comboBox_currentIndexChanged(int index)
    2. {
    3. //do something
    4. }
    To copy to clipboard, switch view to plain text mode 

    But when method retranslateUi() called, I do this:
    Qt Code:
    1. void retranslateUi()
    2. {
    3. ui->comboBox->clear();
    4. ui->comboBox->insertItems(0, QStringList()
    5. << QApplication::translate("SettingDialog", "English", 0, QApplication::UnicodeUTF8)
    6. << QApplication::translate("SettingDialog", "French", 0, QApplication::UnicodeUTF8)
    7. );
    8. }
    To copy to clipboard, switch view to plain text mode 

    Problem is: each statement in retranslateUi() will emit the signal currentIndexChanged(), then the slot will call again.

    How can I avoid that ?
    Last edited by vhptt; 31st July 2012 at 11:20.

  2. The following user says thank you to vhptt for this useful post:


  3. #2
    Join Date
    Oct 2007
    Location
    Lake Forest, CA, USA
    Posts
    132
    Thanks
    10
    Thanked 27 Times in 22 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: Qt Multi language QCombobox problem

    One of the workarounds is to block signals:

    Qt Code:
    1. void retranslateUi()
    2. {
    3. ui->comboBox->blockSignals(true);
    4. ui->comboBox->clear();
    5. ui->comboBox->insertItems(0, QStringList()
    6. << QApplication::translate("SettingDialog", "English", 0, QApplication::UnicodeUTF8)
    7. << QApplication::translate("SettingDialog", "French", 0, QApplication::UnicodeUTF8)
    8. );
    9. ui->comboBox->blockSignals(false);
    10. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by Oleg; 31st July 2012 at 11:28. Reason: spelling corrections
    Oleg Shparber

  4. The following 3 users say thank you to Oleg for this useful post:

    frankiefrank (11th October 2012), vhptt (31st July 2012)

  5. #3
    Join Date
    Jul 2012
    Posts
    20
    Thanks
    8
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4

    Default Re: Qt Multi language QCombobox problem

    Thank you so much. I tried and everything work fine.

  6. The following user says thank you to vhptt for this useful post:


  7. #4
    Join Date
    Dec 2010
    Location
    Israel
    Posts
    90
    Thanks
    59
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Qt Multi language QCombobox problem

    Never saw this blockSignals(). Thanks for the tip!

  8. The following user says thank you to frankiefrank for this useful post:


Similar Threads

  1. Qt Multi language app at runtime
    By vhptt in forum Newbie
    Replies: 2
    Last Post: 23rd July 2012, 15:23
  2. Load multi language fonts at the same time
    By lllturtle in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 12th April 2012, 08:20
  3. Qt Assistant for custom help and multi-language
    By bec in forum Qt Programming
    Replies: 0
    Last Post: 14th April 2011, 08:54
  4. multi language support example
    By Ratheendrans in forum Qt Programming
    Replies: 6
    Last Post: 3rd April 2011, 02:50
  5. Multi language translation
    By bhaskar in forum Installation and Deployment
    Replies: 1
    Last Post: 14th June 2010, 16:30

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.