Fixes another QTranslator related memory leak
authorLuís Pereira <luis.artur.pereira@gmail.com>
Fri, 3 Oct 2014 18:37:11 +0000 (11:37 -0700)
committerLuís Pereira <luis.artur.pereira@gmail.com>
Fri, 3 Oct 2014 19:49:55 +0000 (12:49 -0700)
Delete the QTranslator object if Qt translations aren't found. Warn also.
It's not very likely to happen, but it might happen.

I hate this brace coding style. So much wasted lines.

lxqttranslator.cpp

index 17da24e..04c1646 100644 (file)
@@ -82,9 +82,16 @@ bool Translator::translateApplication(const QString &applicationName)
 {
     QString locale = QLocale::system().name();
     QTranslator *qtTranslator = new QTranslator(qApp);
-    qtTranslator->load("qt_" + locale, QLibraryInfo::location(QLibraryInfo::TranslationsPath));
-    qApp->installTranslator(qtTranslator);
 
+    if (qtTranslator->load("qt_" + locale, QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
+    {
+        qApp->installTranslator(qtTranslator);
+    }
+    else
+    {
+        delete qtTranslator;
+        qWarning("LxQt::Translator: Qt translations not found");
+    }
 
     if (!applicationName.isEmpty())
         return translate(applicationName);