问题
A Qt project gives a number of errors - that I do not actually consider errors I think:
Some examples:
Fontconfig error: "/etc/fonts/conf.d/65-khmer.conf", line 32: out of memory
// ?
QGraphicsItem::ungrabMouse: not a mouse grabber
// i think happens when the mouse grab didn't quite happen, user moved too fast...
A few others
the first one seems it has an answer here https://askubuntu.com/questions/421891/fontconfig-error-out-of-memory
So I cannot fix it through software, the user must fix it... since it is system dependent...
Even built in release, these errors will still show up on command line... Since they do not cause the application to behave abnormally, I don't think the user should see them.
How can I build/deploy the application without these errors showing ?
ideally of course there would be no errors in a deployed application, but I don't know what I can do about those types of errors...
回答1:
It is possible to redirect a stream (in this case stderr
) after the fact using
freopen("/dev/null", "w", stderr);
Just place this in your main
before any other code runs and you should be good. Keep in mind that this might need more work on Windows.
If the error message is posted through the Qt Message infrastructure (qDebug
etc.) you can set a new message handler through the function qInstallMsgHandler.
来源:https://stackoverflow.com/questions/25983408/errors-showing-in-qt-application-how-to-not-display-them-in-release