I am loading a QML file in PyQt application and I would like to display error and warning messages in case QML file is not valid. QQmlApplicationEngine should emit warnings
signal in that case, but that doesn't appear to happen. In code below, if QML file contains errors, it is not loaded but display_warnings
slot is never called. What am I doing wrong? PyQt version is 5.9.
# -*- coding: utf-8 -*-
from PyQt5.QtGui import QGuiApplication
from PyQt5.QtQml import QQmlApplicationEngine
def display_warnings(warnings):
pass # Process warnings
if __name__ == '__main__':
import os
import sys
app = QGuiApplication(sys.argv)
engine = QQmlApplicationEngine()
engine.warnings.connect(display_warnings)
qml_filename = os.path.join(os.path.dirname(__file__), 'MainWindow.qml')
engine.load(qml_filename)
sys.exit(app.exec_())