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. QMessageBox doesn't translate the QString[Solved]
Forum Updated to NodeBB v4.3 + New Features

QMessageBox doesn't translate the QString[Solved]

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 2.4k 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.
  • K Offline
    K Offline
    karim24
    wrote on last edited by
    #1

    @ QInputDialog::getText(this,tr("Open"),tr("New"),QLineEdit::Normal,tr(""),&ok);@

    the translator is loaded and installed but open and new
    don't get translated

    but if i do this :
    @//define Open and New in the mainwindow header file
    QString Open,New;
    //then define a new function
    rename()
    {
    Open=tr("Open");
    New=tr("New");
    }@

    then
    every time i switch the installer i call rename
    @rename();
    QInputDialog::getText(this,Open,New,QLineEdit::Normal,tr(""),&ok);@

    translation works fine

    1 Reply Last reply
    0
    • L Offline
      L Offline
      leon.anavi
      wrote on last edited by
      #2

      Which version of Qt are you using? Do you create instance of QTranslator before the creation of the app's widgets?

      http://anavi.org/

      1 Reply Last reply
      0
      • K Offline
        K Offline
        karim24
        wrote on last edited by
        #3

        hi,thanks ,i'm using 5.0.2

        the problem is that i declared QTranslator ,
        load the file and install it inside a function
        so when it exits it destroys the transltor
        so i removed the definition of the translator
        to the constructor then load and install it in the function

        but don't know why it works fine with rename()

        1 Reply Last reply
        0
        • L Offline
          L Offline
          leon.anavi
          wrote on last edited by
          #4

          [quote author="karim24" date="1378697691"]
          the problem is that i declared QTranslator ,
          load the file and install it inside a function
          so when it exits it destroys the transltor
          so i removed the definition of the translator
          to the constructor then load and install it in the function

          but don't know why it works fine with rename()[/quote]

          Check "the documentation of QTranslator":http://qt-project.org/doc/qt-5.0/qtcore/qtranslator.html and have a look at the notes:

          bq. Note that the translator must be created before the application's widgets.

          Btw the documentation also contains useful examples.

          http://anavi.org/

          1 Reply Last reply
          0
          • K Offline
            K Offline
            karim24
            wrote on last edited by
            #5

            i solved the problem the thing is before it was like this:

            @void retranslate()
            {
            QTranslator translator;//local variable gets destroyed when exiting
            translator.load(path);
            qApp->installTranslator(&translator);
            }@

            and i solved it by moving the declaration of translator to the constructor
            @QTranslator translator;@

            and modified the retranslate() like this
            @void retranslate()
            {
            translator.load(path);
            qApp->installTranslator(&translator);
            }@

            1 Reply Last reply
            0
            • L Offline
              L Offline
              leon.anavi
              wrote on last edited by
              #6

              Well done :) please add prefix [SOLVED] to the title of the thread.

              http://anavi.org/

              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