Is there any way to suppress QML Warnings?
-
If there are any QML errors on a currently rendered QML file, we get the WARN-level logs.
For instance:
WARN - MainPhonePage.qml : : 851 : file:///usr/local/Libs/qml/hmi/phone/MainPhonePage.qml:851: TypeError: Cannot read property 'name' of undefined
WARN - MainPhonePage.qml : : 877 : file:///usr/local/Libs/qml/hmi/phone/MainPhonePage.qml:877: TypeError: Cannot read property 'phoneNumber' of undefined
WARN - MainPhonePage.qml : : 876 : file:///usr/local/Libs/qml/hmi/phone/MainPhonePage.qml:876: TypeError: Cannot read property 'callStatus' of undefinedIs there any way to suppress these warnings? Or stop logging them to the console as part of warnings?
-
@AdarshKale remove the cause of the warnings. Are you getting them on start or on close? Maybe you are calling setContextProperty after loading the QML if it's on start. If it's on close one hypothesis is that some of your objects are destroyed before the QML engine.
-
@GrecKo Yeah, you are right, solving the errors is one of the solutions.
There are many such warnings that come on startup, and this code is carried over from legacy, and to some of the files we do not have access to modify them, So am looking for some way to suppress these.
Anywhere in CMake/QMake (.pro) can we restrict the warnings to be printed on the console?
Thanks -
You can write your own QtMessageHandler in C++ and use
qInstallMessageHandler
I do this in my project, but I take it far in the other direction: my message handler takes every QML "warning" and makes it into a fatal error!
So I agree with @GrecKo that what should ideally happen is that the underlying code that provokes warnings should be fixed so as to no longer provoke warnings.
But I also know the pain of having too much legacy cruft to clean up all at once.
Here is my code, but as I say, it kind of does the opposite of what you want. But it can stand as a starting point regarding
qInstallMessageHandler
: -
Note: I am using QtCreator for SailfishOS, so content may vary between QtCreators used.
Not sure if this helps out or not, perhaps I misunderstand the question (very likely, I often do) I get something similar but it is not a warning, instead is shown as 'unknown'.
In my case, this stems from using QtQuickLayouts, so I get such output as ;
[D] unknown:0 - QQuickLayoutAttached::invalidateItem [D] unknown:0 - QQuickLayoutAttached::invalidateItem [D] unknown:0 - ItemChildAddedChange
such output is spewed out so often, it is hard to see/read warnings and errors I really need to read, I then have to keep scrolling back to see any errors I need to address.
To combat this, while developing my app, on the Compile Output window frame, there is a small search box, I use this to filter out unwanted messages.
-
@KH-219Design Thank you So much for the reference solution.
will tryout this.
Thanks