Important: Please read the Qt Code of Conduct -

qInstallMessageHandler vs. QApplication: order of creation

  • In the Qt documentation of qInstallMessageHandler, there is a little example given where this is called BEFORE the application object is created:

    int main(int argc, char **argv)
         QApplication app(argc, argv);
         return app.exec();

    Is this the required or recommended order? The rest of the documentation doesn't seem to offer an explanation. For almost everything else, it always seems to be necessary to create the application first.

    I suppose that the constructor of app might issue warnings, but that is highly unlikely.

  • @Robert-Hairgrove
    I don't think it matters. I certainly have done qInstallMessageHandler() not as the first statement in my program, rather much later well after QApplication app(argc, argv).

  • @JonB Thanks!

Log in to reply