Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. [Solved] translation doesn't work when executing application
QtWS25 Last Chance

[Solved] translation doesn't work when executing application

Scheduled Pinned Locked Moved Qt Creator and other tools
4 Posts 2 Posters 2.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Ayamou
    wrote on last edited by
    #1

    I am using Qt linguist to translate my application (ui file and the rest of the code). Everything goes alright , the problem is all translations (in ui) work fine except an element added not from designer, here is my code to further explain :

    @ tableWidget = new MyDropTableWidget(ui->verticalLayoutWidget_2);
    if (tableWidget->columnCount() < 1)
    tableWidget->setColumnCount(1);
    tableWidget->setHorizontalHeaderItem(0, new QTableWidgetItem(tr("My non translated text")));
    if (tableWidget->rowCount() < 21)
    tableWidget->setRowCount(21);
    ...
    ui->verticalLayout_2->addWidget(tableWidget);
    ...@

    in main file:
    @QTranslator Translator ;
    qDebug()<<"Translator->load( lang)"<< Translator.load(":/"+language);
    app.installTranslator( &Translator );@

    in mainwindow constructor:

    @ui->retranslateUi(this);@

    all texts in ui are translated fine , only "My non translated text" was not. *.ts file are ok ("My non translated text" was detected and checked) , .qm file are well placed, I rebuild re lupdate re lrelease my application but in vain: when executing my application, all texts are translated expect "My non translated text" still in the source language.

    Any help will be appreciated.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Can you try the hello world translation example from the documentation ? Just to ensure that it's indeed the widget translation that is the problem

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • A Offline
        A Offline
        Ayamou
        wrote on last edited by
        #3

        Hi, thanks for your reply , actually I found the issue reason, the translator was installed after MainWindow constructor call, so when the item is initialized the translator is not set yet, so I fixed it by calling the translation before creating tablewidget :)

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Great !

          Indeed, it must be done before anything else when using widgets. IIRC you can also have your own method that sets every text on your widget and that you call on reaction of QEvent::LanguageChanged.

          Anyway, since you have it working now, please update the thread title prepending [solved] so other forum users may know a solution has been found :)

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved