Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTranslator do not work at all
Qt 6.12 LTS is out! See what's new in the release blog

QTranslator do not work at all

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 1.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.
  • thamT Offline
    thamT Offline
    tham
    wrote on last edited by tham
    #1

    os : windows 10 64 bits
    Qt : 5.9.4, vc2017 64bits

    1. Wrap the text by tr or QObject::tr.
    2. Generate the ts file,
    3. Translate almost every words of the ts file(some of them are left empty).
    4. Run lrelease to generate qm file
    5. Load the qm file as following
    QTranslator custom_translator_;
    qDebug()<<__func__<<a.applicationDirPath();
    if(custom_translator_.load("english_to_turkish.qm", a.applicationDirPath())){
        qDebug()<<__func__<<"can load english to turkish";
        if(a.installTranslator(&custom_translator_)){
            qDebug()<<__func__<<"can install translator";
        }else{
            qDebug()<<__func__<<"cannot install translator";
        }
    }else{
        qDebug()<<__func__<<"cannot load english to turkish";
    }
    

    The return values tell me qm file can be loaded and installed, but none of the text are translated to Turkish, every words remain as English. Any possible wrong I commit? Thanks

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      Do you install your translations before instantiating the GUI or after?

      (Z(:^

      thamT 1 Reply Last reply
      2
      • sierdzioS sierdzio

        Do you install your translations before instantiating the GUI or after?

        thamT Offline
        thamT Offline
        tham
        wrote on last edited by
        #3

        @sierdzio Yes.

        I find out the issue, the problem is life time, I put the QTranslator in a class, and that class is enclosed by {}, that is why the text did not translated, a stupid bug.

        1 Reply Last reply
        1

        • Login

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