How to open a temporary file use QDesktopServices?
I use QTemporaryFile to create a temporary file successfully. But I want to open it by QDesktopServices:
The tempFile seems to be locked by the application. Even I find the tempFile in computer and try to open it Manually, but it can't be done. I try to copy it to other place, and it can be open.
What should I do? Is there have any easy way to solve it?
as long as its not a .exe file, you should be able to
use QTemporaryFile to get file name. delete the QTemporaryFile object to release file
and reuse the tempname for a file you then create normally.
There is also
And dont call filename anything with setup. on windows, its forbidden. :)
UAC eats it in win 10.
I want to use the QTemporaryFile because it has a good function for auto delect all created temporary file. As long as I delete the QTemporaryFile object, all temporary file created by it will be deleted. If I create the tempFile normally, I will not do the job easily. So I want to ask if there have any easy way to do that things?
Not really as you want other process to open it.
So you cannot have it locked in your app.
So you will have to keep track of objects to delete on close.
If was for your own app. then tempfile really good yes.
I found someone encounter the same problem as me and commit to QTBUG a long time ago: https://bugreports.qt.io/browse/QTBUG-10856
Although the behaviour really is not bug and it is by design, but I think it is nessary and I hope QT to add a function for unlock temporary file to solve this problem in the future :)
hi you can easy get same clean up when you die function
using smart pointers. So could make ur own tmp class pretty easy