Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QQmlApplicationEngine engine slow to construct after installing custom message handler



  • Calling QQmlApplicationEngine engine; needs around 8 seconds, if qInstallMessageHandler(myMessageOutput); is called before.
    Without calling qInstallMessageHandler(myMessageOutput); it needs around 400 milliseconds. Used version is Desktop_Qt_5_6_0_MSVC2015_64bit-Debug.

    #include <QGuiApplication>
    #include <QQmlApplicationEngine>
    #include <QElapsedTimer>
    
    void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg)
    {
      return;
    }
    
    int main(int argc, char *argv[])
    {
      QGuiApplication app(argc, argv);
      
      qInstallMessageHandler(myMessageOutput); 
      
      QElapsedTimer timer;
      timer.start();
      QQmlApplicationEngine engine; // This line takes around 8 seconds. But without calling qInstallMessageHandler, it takes around 400 milliseconds. Why? 
      qint64 elapsed = timer.elapsed();
    
      engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    
      return app.exec();
    }
    

Log in to reply