Reputation: 1068
My application displays a grid of images. When the right mouse button is clicked a context menu is displayed where the first option is "Show in Explorer".
I was able to launch the default explorer on the directory by using:
QDesktopServices::openUrl(QUrl::fromLocalFile( directory ));
However I want also the file to be selected.
Is this possible? I suppose it should be, as many apps can do that.
Upvotes: 0
Views: 2909
Reputation: 1068
Ok, I want to thank @Chernobyl for his useful help.
However I've found a general solution posted here: How to "Reveal in Finder" or "Show in Explorer" with Qt
It wasn't compiling at first because the QtCreator code is using a class called Environment which I tried to add to my project but that file then also includes others, etc. I checked and they are using it just to see if explorer.exe can be found on the system path. It was not so important (to me) so I removed that check and then I tested it. It's working perfectly. It's also supposed to work for Mac and Linux.
Upvotes: 0
Reputation: 18514
openUrl
is not suitable here. You need just start another process (with QProcess
start
or startDetached
) with Windows explorer special arguments:
explorer.exe /select,"C:\pathTo\file.txt"
Upvotes: 1