Pau*_*one 4 qt suppress-warnings qml
我不想禁用 QML 的所有警告(如本问题所述)。相反,我想禁用特定类型的警告。就我而言,TypeError: Cannot read property of null警告。
请注意,我认为,我收到此警告是由于Qt 错误在销毁过程中影响孙子元素,而不是任何代码错误的结果。GridView就我而言,每次更改特定模型时,我都会收到很多此类警告(10 到 100 秒) ,因此这些消息在控制台日志中占据主导地位。
我认为高级解决方案可能基于安装自定义消息处理程序并拦截所有警告,过滤掉您想要以不同方式处理的任何警告并绕过其他警告,例如可以处理您的情况:
// 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
...
}
Run Code Online (Sandbox Code Playgroud)