Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Some strings can't be translated in the qt project.

Some strings can't be translated in the qt project.

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 1.5k Views 1 Watching
  • 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.
  • B Offline
    B Offline
    BigCroby
    wrote on last edited by
    #1

    In my qt project, there are some strings can't be translated, such as the following code:

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);

    QTranslator trans;
    trans.load("gui_zh");
    QApplication::installTranslator(&trans);
    ui->retranslateUi(this);
    

    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }

    void MainWindow::on_pushButton_clicked()
    {
    QString fileName = QFileDialog::getOpenFileName(this, tr("open"), QDir::currentPath(), "*.cpp");
    }

    the "open" string , be used in getOpenFileName() function, can't be translated to Chinese string "打开", but other strings, like the pushButton text, can be translated to Chinese string. There is the "Q_OBJECT" in my class, and I have generate *.qm file. I don't know why some stings can be translated, but other strings can't. May I ask for a favor, Thanks!

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

      Hi and welcome to devnet,

      Are you doing dynamic translation with your application ? Or only when starting it ?

      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
      • B Offline
        B Offline
        BigCroby
        wrote on last edited by
        #3

        [quote author="SGaist" date="1388094087"]Hi and welcome to devnet,

        Are you doing dynamic translation with your application ? Or only when starting it ?[/quote]

        Only when starting it, not dynamic translation .

        1 Reply Last reply
        0
        • B Offline
          B Offline
          BigCroby
          wrote on last edited by
          #4

          [quote author="SGaist" date="1388094087"]Hi and welcome to devnet,

          Are you doing dynamic translation with your application ? Or only when starting it ?[/quote]

          Are there some differences between dynamic translation and only when starting it?

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

            You should move the translator related code in your main function. The translator must be installed before creating any widgets. Have a look at the QTranslator documentation for more information

            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