How to translate the OK and Cancel buttons of the static QMessageBox functions

I'm using the static QMessageBox functions for a small download tool I wrote. Unfortunately, I struggled a little bit with the translation of the OK and Cancel buttons. There is some information available by asking uncle google, but the information revealed seems not 100% correct for Qt 5.3.

What you need to do is to load the Qt translation file in addition to your original .qm file(s) at the same time you load your own translation file(s). The file is located in the translation sub-folder of your Qt installation folder. For the OK and Cancel buttons you would need to load the qtbase_XX where XX should be replaced with your locale:

int main(int argc, char *argv[])
  QApplication a(argc, argv);

  // Own translation file
  QTranslator translator;
  translator.load(a.applicationName() + _ + QLocale::system().name(), a.applicationDirPath());

  // Translation file for Qt stuff
  QTranslator translator2;
  translator2.load(qtbase_ + QLocale::system().name(), a.applicationDirPath());

  MainWidget wid;
  return a.exec();

Original Qt FAQ: [Technical_FAQ#How_can_I_translate_the_OK_and_Cancel_buttons...](


Hope this is of some help.