[go: up one dir, main page]

Skip to content

No need to include QCoreApplication

Currently, the library QCoreApplication is included just to invoke QCoreApplication::installTranslator() in a procedural fashion. However, QApplication implements the same function in an object-oriented manner, as a function of the object itself. Thus, main() could be rewritten:

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QTranslator translator;
    if (!translator.load("cp2130-conf_" + QLocale::system().name(), ":/translations/translations")) {  // It the locale translation does not exist or cannot be loaded
        translator.load("cp2130-conf_en_US", ":/translations/translations");  // Fall back to the en-US translation
    }
    a.installTranslator(&translator);  // Replaces QCoreApplication::installTranslator(&translator)
    MainWindow w;
    w.show();
    return a.exec();
}

This approach is more object-oriented, and QCoreApplication doesn't need to be included.