Hi all,
My system is Windows7 32-bit with Qt SDK 4.8.4 with VS2010 and MinGW compilers. Qt Creator 2.4.1
I have a application where I am getting a list of files from server in a QTreeWidget and I have the option of Downloading as well as well Open the file from the list.
In case of 'Open' action, the file is downloaded through HTTP in a temp location and it is opened through QDesktopServices:penUrl() functionality.
Now I use the following code for this:
Qt Code:
  1. if (open)
  2. { file = new QTemporaryFile(QDir::tempPath() + "/XXXXXX." + fileName);}
To copy to clipboard, switch view to plain text mode 

After file is downloaded, open action is triggered as below:
Qt Code:
  1. file->close();
  2. if(file->isOpen())
  3. qDebug() << "File still opened.";
  4. if (open)
  5. QDesktopServices::openUrl("file:///" + file->fileName());
To copy to clipboard, switch view to plain text mode 


With this code, the file is getting downloaded properly in Temporary path(C:\Users\James\AppData\Local\Temp) but it is not getting opened through QDesktopServices. It is giving error that file is currently opened with another program. On further debugging, I found the application itself is having a hold of that downloaded file. The file is getting closed properly with file->close(). Another observation is it opens small files... like upto 10KB text files.

Now, if I replace the replace the above code with QDesktopServices::storageLocation(), it works perfectly. See below code:
Qt Code:
  1. if (open)
  2. {
  3. file = new QFile(QDesktopServices::storageLocation(QDesktopServices::TempLocation) + "/" + fileName);
  4. }
To copy to clipboard, switch view to plain text mode 

Is this an issue with QTemporaryFile class? Need help seriously.

Regards,
Girish