qt中打开目录并且选中文件

该方法完美解决了,打开文件名含有空格,导致文件夹打开位置不对的bug。

QProcess process;
QString filePath = currentitem->path;
QString cmd = QString("explorer /select, \"%1\"").arg(QDir::toNativeSeparators(filePath));
process.startDetached(cmd);

备注:
1.explorer不能包含.exe
2.利用QDir::toNativeSeparators处理要打开的文件路径,需要引入#include <QDir>

Last modification:February 17th, 2020 at 12:23 pm
如果觉得我的文章对你有用,请随意赞赏

Leave a Comment