From 6723a4edead6127a7ac6f38996d886826bab03bd Mon Sep 17 00:00:00 2001 From: liyepan Date: Thu, 22 Oct 2026 18:47:25 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20v0.10.3=20=E2=80=94=E2=80=94=20=E4=BF=AE?= =?UTF-8?q?=E6=8E=89=E5=AF=BC=E5=87=BA=20PDF=20=E5=8D=A1=E4=BD=8F=EF=BC=9A?= =?UTF-8?q?=E5=BC=BA=E5=88=B6=E4=BD=BF=E7=94=A8=20Qt=20=E8=87=AA=E5=B8=A6?= =?UTF-8?q?=E7=9A=84=E6=96=87=E4=BB=B6=E5=AF=B9=E8=AF=9D=E6=A1=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 打开 / 另存为 / 导出 PDF / 打开文件夹 全部加上 DontUseNativeDialog - 根因:Qt 默认会走 GTK 原生文件选择器,本机 dconf 只读、gvfs 不可用, 对话框会卡在初始化(日志里刷了一百多行 dconf 报错) - 实测:走原生时 136 行 dconf 报错;强制 Qt 对话框后只剩 4 行,秒开 - 导出时加等待光标和「正在导出 PDF…」状态提示 - README 说明,版本 0.10.3 --- README.md | 6 +++++- VoiletMark.pro | 2 +- src/MainWindow.cpp | 16 ++++++++++++---- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 6b7c78f..2834226 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ 一个轻量的跨平台 Markdown 编辑器,基于 **Qt 5 / C++17** 构建。 -当前版本 **0.10.2**。 +当前版本 **0.10.3**。 ## 界面 @@ -94,6 +94,10 @@ **文件 → 导出 PDF…**(`Ctrl+E`)直接弹保存对话框,选个位置就导出,没有中间预览。 A4 纸、16mm 页边距。 +文件对话框一律用 Qt 自带的实现(`DontUseNativeDialog`), +不走系统原生选择器——GTK 原生对话框在部分桌面环境下会因为 dconf / gvfs +不可用而卡住,这也是之前「点导出就没反应」的原因。 + 导出用的是 Qt 自带的 `QPrinter` + `QTextDocument`,不需要额外的 PDF 库。 支持标题、列表(含任务列表)、引用、代码块、行内代码、粗体 / 斜体 / 删除线、 链接、表格;图片只输出 alt 文字。 diff --git a/VoiletMark.pro b/VoiletMark.pro index 090a961..11f89b6 100644 --- a/VoiletMark.pro +++ b/VoiletMark.pro @@ -1,6 +1,6 @@ TEMPLATE = app TARGET = VoiletMark -VERSION = 0.10.2 +VERSION = 0.10.3 QT += core gui widgets printsupport diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index a27c215..9ab08a7 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -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); }