QQmlComponent ReferenceError not coming through via errors()
I use the following code to test if a QML script compiles before embedding it in a bigger script:
m_scriptComponent = new QQmlComponent(m_liveView->quickView()->engine());
m_scriptComponent->setData("import QtQuick 2.0\n" + m_scriptText.toUtf8(), QUrl());
QList<QQmlError> scriptErrors = m_scriptComponent->errors();
This works fine and scriptErrors is filled when most errors occur. What does NOT get reported is ReferenceErrors. Say I have the script line:
property bool bla: fals
I get the following error in the application output, but not in errors():
qrc:/renderScript:7: ReferenceError: fals is not defined
What should I do to retrieve those errors?!
I remember having to do something similar where I would display all qml errors to the user.
I'm not sure if there is a cleaner way to do this but what I did was to install a new message handler and then intercept application messages and filter errors.
I guess you can have a global error list that gets populated by a custom message handler which you can then access from anywhere in your application. Maybe you can clear the list after each access. Depends on your requirements.
Or you could have multiple lists e.g: qmlReferenceErrors, qmlScriptErrors, etc, which would also be populated by a custom message handler.
I do not remember finding a list of reference errors anywhere.
Please do let us know if you find a cleaner way to do this.
Thanks for answering. Will try this out when I find time.
Could you elaborate on what message handle to install. I'm a newbie to QML, so I don't really have an idea what to use... :/