[英]How to disable specific QML debugger warning
我不想禁用所有来自QML的警告( 如本问题所述 )。 相反,我想禁用特定类型的警告。 在我的情况下, TypeError: Cannot read property of null
警告的TypeError: Cannot read property of null
。
请注意,我收到此警告是由于Qt错误造成的,该错误会在孙子元素销毁期间影响子元素 ,而不是任何代码错误的结果。 就我而言,每次更改特定的GridView
模型时,都会收到很多这样的警告(10s到100s),因此这些消息在控制台日志中占主导地位。
我认为高级解决方案可能基于安装自定义消息处理程序并拦截所有警告,过滤出您想以其他方式处理的所有警告并绕过其他警告,例如,这可以处理您的情况:
// Default message handler to be called to bypass all other warnings.
static const QtMessageHandler QT_DEFAULT_MESSAGE_HANDLER = qInstallMessageHandler(0);
// a custom message handler to intercept warnings
void customMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString & msg)
{
switch (type) {
case QtWarningMsg: {
if (!msg.contains("TypeError: Cannot read property of null")){ // suppress this warning
(*QT_DEFAULT_MESSAGE_HANDLER)(type, context, msg); // bypass and display all other warnings
}
}
break;
default: // Call the default handler.
(*QT_DEFAULT_MESSAGE_HANDLER)(type, context, msg);
break;
}
}
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
qInstallMessageHandler(customMessageHandler); // install custom msg handler
...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.