[ACCEPTED]-loading qm file using QTranslator-translation

Accepted answer
Score: 25

Where are the .qm files located? Your code 7 is attempting to load the file from the 6 current working directory, which can be 5 anything during runtime. Specify a directory 4 path in the call to QTranslator::load:

QTranslator* translator = new QTranslator();
if (translator->load("hellotr_la", "/path/to/folder/with/qm/files")) {

Translations can be 3 loaded from Qt resources, so it is a good idea to bundle 2 them inside your executables. Then you would 1 load them somewhat like this:

QTranslator* translator = new QTranslator();
if (translator->load("hellotr_la", ":/resources/translations")) {
Score: 3

The answer was already given in a comment, but 8 I want to point it out clearly.

The first 7 warning uses a wrong condition:

    qWarning("failed-no file");

It should 6 be:

    qWarning("failed-no file");

Since you only saw the second warning, but 5 not the first one, the problem is indeed 4 that the file was not found. Make sure that 3 the working directory is what you expect 2 it to be or (better) use the resource system 1 as explained by andref.

Score: 0

Based on the example, can you simply try 3 this :

 QTranslator translator;

Hope it will fix your problem !

Note 2 1 : No pointer here.
Note 2 : No extension 1 in your filename.

More Related questions