How to report errors from custom QML components?
-
Today, I encounter a error:
Histogram_Plot.qml:95 Cannot assign to non-existent property "onDragChanged"
Which is report by qmlscene.exe when I preview it. But When I wanna run the whole application, I got a white window. My
main()
useQQmlApplicationEngine
, code as following:QQmlApplicationEngine engine; //other coding about initializing engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
How could I locate error like qmlscene.exe reports when run application in the QtCreator.
-
Is Histogram_Plot.qml a file from your project? Then go to line 95 in that file - this is where the error lies.
-
@Crawl-W
https://doc.qt.io/qt-5/qqmlapplicationengine.html#load-1 says:If an error occurs, error messages are printed with
qWarning.
You could look at accessing those via https://doc.qt.io/qt-5/qtglobal.html#qInstallMessageHandler.
Or, what about https://doc.qt.io/qt-5/qqmlengine.html#warnings.
?
-
@JonB said in How to report errors from custom QML components?:
uld look at accessing tho
I tried the following code:
QQmlApplicationEngine engine; QObject::connect(&engine, &QQmlApplicationEngine::warnings, [](const QList<QQmlError> warnings){qDebug() << warnings;});
But, I got nothing.May there are no
QQmlError
being reported.
Have you encountered such a problem? Any tricks? -
@Crawl-W
Then you do need to go down the https://doc.qt.io/qt-5/qtglobal.html#qInstallMessageHandler link route I showed you first. AllqWarning()
etc. messages go via this. You can write your own interceptor code and do whatever you want with the messages. -
@JonB said in How to report errors from custom QML components?:
. messages go via this. You can write your own interceptor code and do whatever you want with the messages.
Still can't catch any exceptions. Direct run does not seem to do the inspection of qml objects, but qmlscene.exe does.
-
Maybe there's no error, try adding an obvious syntax error in your code and watch the log.
Warning and errors are written to the console output by default.