Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Can't open selected file in windows explorer from application
Niagarer last edited by
I try to open a file in the explorer (OS independent in the end). That's what I try on windows:
QStringList args; args << "/select," << QDir::toNativeSeparators("G:/test.txt"); QProcess::startDetached("explorer", args);
This test.txt is definately there, but when I call this, it just opens the explorer, not the selected directory or file.
What did I miss?
Thanks for answers!
are u sure the "/select," << comma is correct ?
I took that from
Yes, there it seems to work
Its also possible to use Desktop services and do
to open it in default app,
but you seem to want to open explorer and have it selected?
(which samples is for. not to launch the app for edit. )
it works here
it will open folder select the file. as it should.
(it does not open the file but that is not expected)
Yes, I create several text files while runtime and by clicking on a button, I want to open one specific (depending on the button) selected in the explorer (not in a text editor), not in the browser
well I found a text file, that works (I just tried randomly):
// this works args << "/select," << QDir::toNativeSeparators("C:/Program Files/Autodesk/Maya2018/bin/MTTH.txt"); QProcess::startDetached("explorer", args);
but yet I could not find any other text file, that works. Not on the G disk, not on the C, that's the only one
so it should just open explorer and show file as selected ?
you code works for me on win 10.
It will open the drive and have the file selected.
QStringList args; args << "/select," << QDir::toNativeSeparators("c:/degree-angles.png"); QProcess::startDetached("explorer", args);
Tried a few different file and all types seems to work.
Ok weird then, I also tried on win 10 ...
I can't find differences between the files I tried... only MTTH.txt works
Oh, ok it seems to be a general problem with my system... I also can't open it from cmd like you tried... it opens my dcuments then... So it seems not to be a qt problem
All files work here. Even folders.
I also tried other drives and so i agree must be something locally
in your system. ( no idea what though)
Ok, yes I even can't open the MTTH.txt file from cmd, it just opens my documents folder every time...
I have no idea... I hope I can fix this
Thanks for your help!
I can open the files with a notepad, but not with the explorer. So my explorer seems to be sick.
I will update anyways when I have a solution
For test, try disable any extra virus scanner you have installed.
Niagarer last edited by
unfortunately doesn't help :/
Would have been too easy. ;)
did you try with quotes ?
Yup, unfortunately also no solution... but then it does not open my documents folder, it just open the explorer
Slowly but surely it start to get funny
When I try to select, it just opens the explorer, if not, it opens the documents folder
well it does open docs here too if no /select
if i do
.. /select,"file that dont exists"
it opens "This PC"
yes, the weird thing is, that the explorer defiantely knows the file. I even can search in the explorer search line and it finds the file.
But as you wrote, from cmd it can't find the file...
I can navigate to the right folder on the G drive, it still can't find the file
But its only /select that is broken correct?
if you do other commands it does work?
No, I don't think so.
All the following commands don't work:
// here it says, it could find that file... it is definately there notepad G:/test.txt explorer G:/ explorer /select G:/test.txt
and g:\ is just another hard drive or partition ?
Like c:\ ?
But it dont work at c:\ either so must be something broken in your windows.
you must use \ that slash. not / .
Qt makes it possible to use / but windows dont know it natively.
Ok, I got it. Yes G is just another drive and it didn't work on any drive because:
I also noticed this \ and / thing and this was one of my mistakes.
Another thing, why cmd could not find one of my test.txt files I tried to open was that I named it test.txt (so the actual file name was test.txt.txt as my browser told me <facepalm x3>).
And one last thing, that is no less stupid is, that I sent the path from another object and this object did not send the .txt ending. Baad day :D
And I copied the path of some text files from the explorer and tried these, but the \ made it not working.
I thought that
would fix \ to / (or \ on windows), but that seems to be wrong. It just takes normal paths with / and translates it to \ on windows http://doc.qt.io/qt-4.8/qdir.html#toNativeSeparators
Thank you very much for you help!
Ahh that is a classic :)))
I forgot about it.
Most stupid settings the history of windows as renaming the file will not actually work and you
get 2 x extension.