fix: v0.10.3 —— 修掉导出 PDF 卡住:强制使用 Qt 自带的文件对话框

- 打开 / 另存为 / 导出 PDF / 打开文件夹 全部加上 DontUseNativeDialog
- 根因:Qt 默认会走 GTK 原生文件选择器,本机 dconf 只读、gvfs 不可用,
  对话框会卡在初始化(日志里刷了一百多行 dconf 报错)
- 实测:走原生时 136 行 dconf 报错;强制 Qt 对话框后只剩 4 行,秒开
- 导出时加等待光标和「正在导出 PDF…」状态提示
- README 说明,版本 0.10.3
This commit is contained in:
2026-10-22 18:47:25 +08:00
parent cf05de24f5
commit 6723a4edea
3 changed files with 18 additions and 6 deletions
+12 -4
View File
@@ -612,7 +612,8 @@ void MainWindow::openFile()
const QString path = QFileDialog::getOpenFileName(
this, tr("打开 Markdown 文件"), startDirectory(),
tr("Markdown 文件 (*.md *.markdown *.mdown *.mkd);;文本文件 (*.txt);;所有文件 (*)"));
tr("Markdown 文件 (*.md *.markdown *.mdown *.mkd);;文本文件 (*.txt);;所有文件 (*)"),
nullptr, QFileDialog::DontUseNativeDialog);
if (path.isEmpty())
return;
openPath(path);
@@ -665,7 +666,8 @@ bool MainWindow::saveFileAs()
{
QString path = QFileDialog::getSaveFileName(
this, tr("另存为"), startDirectory(),
tr("Markdown 文件 (*.md);;文本文件 (*.txt);;所有文件 (*)"));
tr("Markdown 文件 (*.md);;文本文件 (*.txt);;所有文件 (*)"),
nullptr, QFileDialog::DontUseNativeDialog);
if (path.isEmpty())
return false;
@@ -683,12 +685,14 @@ void MainWindow::exportPdf()
QString target = QFileDialog::getSaveFileName(
this, tr("导出 PDF"), QDir(startDirectory()).filePath(suggested),
tr("PDF 文件 (*.pdf)"));
tr("PDF 文件 (*.pdf)"), nullptr, QFileDialog::DontUseNativeDialog);
if (target.isEmpty())
return;
if (!target.endsWith(QStringLiteral(".pdf"), Qt::CaseInsensitive))
target += QStringLiteral(".pdf");
statusBar()->showMessage(tr("正在导出 PDF…"));
QTextDocument document;
MarkdownRenderer::render(m_editor->toPlainText(), &document);
document.setPageSize(QSizeF(672.76, 1001.57));
@@ -699,7 +703,10 @@ void MainWindow::exportPdf()
printer.setPageSize(QPageSize(QPageSize::A4));
printer.setPageMargins(QMarginsF(16, 16, 16, 16), QPageLayout::Millimeter);
printer.setDocName(QFileInfo(target).completeBaseName());
QApplication::setOverrideCursor(Qt::WaitCursor);
document.print(&printer);
QApplication::restoreOverrideCursor();
if (!QFileInfo::exists(target) || QFileInfo(target).size() <= 0) {
QMessageBox::warning(this, tr("导出失败"),
@@ -971,7 +978,8 @@ void MainWindow::refreshRecentMenu()
void MainWindow::chooseFolder()
{
const QString directory = QFileDialog::getExistingDirectory(
this, tr("打开文件夹"), startDirectory(), QFileDialog::ShowDirsOnly);
this, tr("打开文件夹"), startDirectory(),
QFileDialog::ShowDirsOnly | QFileDialog::DontUseNativeDialog);
if (!directory.isEmpty())
openFolder(directory);
}