I using explorer for show files and "select" in Windows 7 and Windows 8, like this:
explorer /select,c:\foo\bar\baz.txt
In Qt I tried use:
const QString filepath = a.applicationDirPath() + "\\.txt";
QStringList params = QStringList() << "/select," << filepath;
QProcess::startDetached("explorer", params);
Work fine in Windows 10, but not work in Windows 7 and 8 if file path contains unicode characters ("emojis").
In my folder I put two files in release folder:
app.exe
.txt
My source:
#include <QCoreApplication>
#include <QProcess>
#include <QDebug>
#include <QDir>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
const QString name = ".txt";
const QString filepath = QDir::toNativeSeparators(a.applicationDirPath() + "\\" + name);
QStringList params = QStringList() << "/select," << filepath;
qDebug().noquote() << "explorer " + params.join("");
QProcess::startDetached("explorer", params);
return a.exec();
}
I tried use chcp 65001
:
QProccess::execute("chcp 65001");
QProccess::startDetached("explorer", params);
After I tried:
const QString name = QString::fromWCharArray(L".txt");
And:
const QString name = QString::fromStdWString(L".txt");
But not work.
How "encode" filepath
for use with /select,
argument? Or is it not possible to use unicode in Windows 7 and Windows 8?