Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Problem with Translation of qMessageBox



  • Hello
    I've got an problem with the translation of an MessageBox Object
    The translation overall works, only the Messagebox is not translated.

    void MainWindow::SerialnumberUnequal(QString qSerialnumberConfig, QString qSerialnumberAlarm, QString qSerialnumberLogging)
    {
        QMessageBox SerialnumberDialog;
        QString str;
        str = trUtf8("Serialnumber from Configuartion Page: %1\nSerialnumber from Alarm Page: %2\nSerialnumber from Logging Page: %3").arg(qSerialnumberConfig).arg(qSerialnumberAlarm).arg(qSerialnumberLogging);
        SerialnumberDialog.setWindowTitle(tr("Which Serialnumber should be used?"));
        SerialnumberDialog.setText(str);
        QPushButton *setSerConfig = SerialnumberDialog.addButton(trUtf8("Take Serialnumber \n from Configuration Page"), QMessageBox::ActionRole);
        QPushButton *setSerAlarm = SerialnumberDialog.addButton(trUtf8("Take Serialnumber \n from Alarm Page"), QMessageBox::ActionRole);
        QPushButton *setSerLogging = SerialnumberDialog.addButton(trUtf8("Take Serialnumber \n from Logging Page"), QMessageBox::ActionRole);
        SerialnumberDialog.exec();
        if (SerialnumberDialog.clickedButton()==setSerConfig) {
            if(ui->SerialNumberConfiguration->text().length()==10) {
                ui->SerialNumberAlarm->setText(ui->SerialNumberConfiguration->text());
                ui->SerialNumberLogging->setText(ui->SerialNumberConfiguration->text());
            } else {
                SerialnumberDialog.warning(nullptr, trUtf8("Warning"), trUtf8("Selected serial number does not consist of 10 characters"));
            }
        } else if (SerialnumberDialog.clickedButton()==setSerAlarm) {
            if(ui->SerialNumberAlarm->text().length()==10) {
                ui->SerialNumberConfiguration->setText(ui->SerialNumberAlarm->text());
                ui->SerialNumberLogging->setText(ui->SerialNumberAlarm->text());
            } else {
               SerialnumberDialog.warning(nullptr, trUtf8("Warning"), trUtf8("Selected serial number does not consist of 10 characters"));
            }
        } else if (SerialnumberDialog.clickedButton()==setSerLogging) {
            if(ui->SerialNumberLogging->text().length()==10) {
                ui->SerialNumberAlarm->setText(ui->SerialNumberLogging->text());
                ui->SerialNumberConfiguration->setText(ui->SerialNumberLogging->text());
            } else {
                SerialnumberDialog.warning(nullptr, trUtf8("Warning"), trUtf8("Selected serial number does not consist of 10 characters"));
            }
        }
    }
    

    this is my implementation of the messagebox. Have I made a mistake around here somewhere?
    Thanks a lot
    Seprim



  • The problem is solved.
    I was the problem.
    I program with Visual Studio and MSVC and here an extra subfolder Release/Debug is created in which the EXE file is stored. I have to put my languages folder here for the translation to work.
    Sorry for the mail.



  • @seprim said in Problem with Translation of qMessageBox:

    trUtf8

    Is trUtf8 not obsolete ?
    Also this may be helpfull.



  • I've also tried only tr and this did not work also.
    The solution from stackoverflow site i've tried also but with no success
    The translation works for

     SerialnumberDialog.setWindowTitle(tr("Which Serialnumber should be used?"));
    

    But no where else.
    The other text contains "\n". Could this be the problem?



  • @seprim said in Problem with Translation of qMessageBox:

    QPushButton *setSerConfig = SerialnumberDialog.addButton(trUtf8("Take Serialnumber \n from Configuration Page"), QMessageBox::ActionRole);

    What are you trying to achieve with this?



  • I create a button with an Action Role. And this button should be translated.
    Actual the Code looks like this

    void MainWindow::SerialnumberUnequal(QString qSerialnumberConfig, QString qSerialnumberAlarm, QString qSerialnumberLogging)
    {
        QMessageBox SerialnumberDialog;
        QString str;
        str = tr("Serialnumber from Configuartion Page: %1\nSerialnumber from Alarm Page: %2\nSerialnumber from Logging Page: %3").arg(qSerialnumberConfig).arg(qSerialnumberAlarm).arg(qSerialnumberLogging);
        SerialnumberDialog.setWindowTitle(tr("Which Serialnumber should be used?"));
        SerialnumberDialog.setText(str);
        QPushButton *setSerConfig = SerialnumberDialog.addButton(tr("Take Serialnumber \n from Configuration Page"), QMessageBox::ActionRole);
        QPushButton *setSerAlarm = SerialnumberDialog.addButton(tr("Take Serialnumber \n from Alarm Page"), QMessageBox::ActionRole);
        QPushButton *setSerLogging = SerialnumberDialog.addButton(tr("Take Serialnumber \n from Logging Page"), QMessageBox::ActionRole);
        SerialnumberDialog.exec();
        if (SerialnumberDialog.clickedButton()==setSerConfig) {
            if(ui->SerialNumberConfiguration->text().length()==10) {
                ui->SerialNumberAlarm->setText(ui->SerialNumberConfiguration->text());
                ui->SerialNumberLogging->setText(ui->SerialNumberConfiguration->text());
            } else {
                SerialnumberDialog.warning(nullptr, tr("Warning"), tr("Selected serial number does not consist of 10 characters"));
            }
        } else if (SerialnumberDialog.clickedButton()==setSerAlarm) {
            if(ui->SerialNumberAlarm->text().length()==10) {
                ui->SerialNumberConfiguration->setText(ui->SerialNumberAlarm->text());
                ui->SerialNumberLogging->setText(ui->SerialNumberAlarm->text());
            } else {
               SerialnumberDialog.warning(nullptr, tr("Warning"), tr("Selected serial number does not consist of 10 characters"));
            }
        } else if (SerialnumberDialog.clickedButton()==setSerLogging) {
            if(ui->SerialNumberLogging->text().length()==10) {
                ui->SerialNumberAlarm->setText(ui->SerialNumberLogging->text());
                ui->SerialNumberConfiguration->setText(ui->SerialNumberLogging->text());
            } else {
                SerialnumberDialog.warning(nullptr, tr("Warning"), tr("Selected serial number does not consist of 10 characters"));
            }
        }
    }
    


  • This post is deleted!


  • The problem is solved.
    I was the problem.
    I program with Visual Studio and MSVC and here an extra subfolder Release/Debug is created in which the EXE file is stored. I have to put my languages folder here for the translation to work.
    Sorry for the mail.


Log in to reply