Unsolved Supress warnings/errors from Qt classes?
-
In my code I sometimes see warnings/errors from Qt classes - some of which I have no control over e.g .if I check that a socket is open and start writing to it, but underlying socket closes during that time, it will result in an ERROR entry in the log file. Similarly, if a png file is loaded with invalid profile, it will generate a invalid RGB profile warning.
Even though program isn't affected by it, I want to suppress these errors without completely disabling logging in my project. Is there a way to suppress Errors/Warnings for specific or all Qt classes?
-
Hi
Not that i have seen.
You can redirect qDebug/QWarning etc and also disable it , but not
as on a pr class basic as far as i know. -
@Taytoo
You may be able to achieve what you want.Look at https://doc.qt.io/qt-5/qtglobal.html#qInstallMessageHandler. All [most! well-behaved!] messages go through here, including
qDebug()
etc. Although you cannot do something like "suppress messages from certain classes" --- the class issuing a message isn't even passed around as a parameter --- you might be prepared to recognise certain message texts and chose not to output them. That's the best you can do, which is what @mrjj was referring to with "You can redirect qDebug/QWarning etc". -
Hi,
One thing to take into account is that not all these warming and errors come from Qt. For example the png message comes from libpng directly.
-
@mrjj I already have a messagehandler that I use to write logs in custom format. Thought about filtering string in there but it'll add too much overhead comparing each string that's being written to log.
@SGaist True about libpng, but that's just warning and is written only when the image is loaded, however, socket error is written out each time a socket closes unexpectedly while i'm writing to it. The error makes it look like something went really wrong but its just a benign message.
-
Use categeorized logging für your logs and all which has no category can be ignored.