怎么在qt中打开系统文件浏览器,并选中文件呢?搬自https://stackoverflow.com/questions/3490336/how-to-reveal-in-finder-or-show-in-explorer-with-qt
// windowds
void OpenFileInExplorer()
{
QString path = "C:/exampleDir/example.txt";
QStringList args;
args << "/select," << QDir::toNativeSeparators(path);
QProcess *process = new QProcess(this);
process->start("explorer.exe", args);
}
// mac
void showFileInFolder(const QString &path){
#ifdef _WIN32 //Code for Windows
QProcess::startDetached("explorer.exe", {"/select,", QDir::toNativeSeparators(path)});
#elif defined(__APPLE__) //Code for Mac
QProcess::execute("/usr/bin/osascript", {"-e", "tell application \"Finder\" to reveal POSIX file \"" + path + "\""});
QProcess::execute("/usr/bin/osascript", {"-e", "tell application \"Finder\" to activate"});
#endif
}
以上只摘了部分代码,完整的代码,可自行查看!
网友评论