首页 > 解决方案 > 为什么调用 QFileDialog::getSaveFileName() 会在 Linux 上重置已安装的 Qt 消息处理程序?

问题描述

调用对话框会重置 debian(如 linux)中的消息处理程序

是的,这里不再需要详细信息,但我必须添加此文本才能通过智能机器人

#include <QApplication>
#include <QFileDialog>
#include <QDebug>

QtMessageHandler defaultHandler;

void messageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
    auto str = msg;
    str.append(" handled");
    defaultHandler(type, context, str);
}

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    qDebug() << "test0";
    defaultHandler = qInstallMessageHandler(messageHandler);
    qDebug() << "test1";
    QFileDialog::getSaveFileName();
    qDebug() << "test2";
}

在窗口中输出

test0
test1 handled
test2 handled

像linux一样在debian中输出

test0
test1 handled
warning: QFSFileEngine::open: No file name specified
debug: test2

标签: c++linuxqt

解决方案


推荐阅读