打开文件所在目录并选择该文件

打开文件所在目录并选择该文件

windows实现方式:

QString strTempPath = "/select,";
strTempPath = strTempPath + QDir::toNativeSeparators(strFilePath);
ShellExecuteW(NULL, TEXT("open"), TEXT("Explorer.exe"), strTempPath.utf16(), NULL, SW_SHOWNORMAL);

mac实现方式:

QStringList scriptArgs;
scriptArgs << QLatin1String("-e")
               << QString::fromLatin1("tell application "Finder" to reveal POSIX file "%1"")
                    .arg(strFilePath);
QProcess::execute(QLatin1String("/usr/bin/osascript"), scriptArgs);
scriptArgs.clear();
scriptArgs << QLatin1String("-e")
               << QLatin1String("tell application "Finder" to activate");
QProcess::execute("/usr/bin/osascript", scriptArgs);
原文地址:https://www.cnblogs.com/sz-leez/p/4264801.html