Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Issue with QTemporaryFile() class in Windows
Forum Updated to NodeBB v4.3 + New Features

Issue with QTemporaryFile() class in Windows

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 865 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    blueshift
    wrote on last edited by
    #1

    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::openUrl() functionality.
    Now I use the following code for this:
    @
    if (open)
    file = new QTemporaryFile(QDir::tempPath() + "/XXXXXX." + fileName);
    @

    After file is downloaded, open action is triggered as below:
    @
    file->close();
    if(file->isOpen())
    qDebug() << "File still opened.";
    if (open)
    QDesktopServices::openUrl("file:///" + file->fileName());
    @

    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:
    @
    if (open)
    {
    file = new QFile(QDesktopServices::storageLocation(QDesktopServices::TempLocation) + "/" + fileName);
    }
    @

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

    Regards,
    Girish

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved