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
+5 -1
View File
@@ -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 文字。
+1 -1
View File
@@ -1,6 +1,6 @@
TEMPLATE = app
TARGET = VoiletMark
VERSION = 0.10.2
VERSION = 0.10.3
QT += core gui widgets printsupport
+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);
}