[SOLVED] how to translate model dialogs in addition to mainwindow?



  • Hi all, my qt application could switch languages in mainwindow. But the 'tr' is not working in modal dialogs. Could anybody do me a help? Thanks in advance.

    TS file and QM file already contain correct translations.

    @
    /* Modal Dialog Header File */
    class DTRuleDialog : public QDialog
    {
    Q_OBJECT
    public:
    explicit DTRuleDialog(QWidget *parent = 0);
    QLabel *labelFollow;
    }
    @

    @
    /* Modal Dialog CPP File */
    DTRuleDialog::DTRuleDialog(QWidget *parent) :
    QDialog(parent)
    {
    labelFollow = new QLabel(tr("Follow"));
    }
    @

    @
    /* MainWindow CPP File */

    DTMainWindow::DTMainWindow()
    {
    btnCustomize = new QPushButton("");
    connect(btnCustomize, SIGNAL(clicked()), SLOT(rule()));
    }

    void DTMainWindow::rules()
    {
    DTRuleDialog *ruleDialog = new DTRuleDialog(this);
    ruleDialog->exec();
    }
    @


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Maybe a silly question, but are you loading the translation file properly in your application ?



  • OK. Problem is solved by having different context name for different widgets in TS file.

    @
    <context>
    <name>MainWindow</name>
    blabla
    </context>
    <context>
    <name>ModalDiaglog</name>
    blabla
    </context>
    @


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.