【QT】选择和打开中文路径文件目录

场景: Qt选择和打开目录,支持中文、空格等

实现:

# 选择目录
QString strDir = "D:\\";
QString qslPath = QFileDialog::getExistingDirectory(this, "", strDir);
ui->l_path->setText(qslPath);

# 打开目录
QString path = ui->l_path->text();
if (!path.isEmpty()) QDesktopServices::openUrl(QUrl::fromLocalFile(path));

关键: QUrl::fromLocalFile(path)

示例:

posted @ 2024-01-27 10:11  hely_ljm  阅读(896)  评论(0)    收藏  举报