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. Qt file resize behaves weirdly in Linux

Qt file resize behaves weirdly in Linux

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 1.2k 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.
  • A Offline
    A Offline
    adnan
    wrote on last edited by
    #1

    Here is my code snippet

    @QFile temfile(fileUrl);
    if(temfile.open(QIODevice::WriteOnly) == false)
    {
    qDebug()<<"Unable to create file!";
    return;
    }
    if(temfile.resize(5073741824) == false) // 5GB
    {
    qDebug()<<"Insufficient disk space!";
    return;
    }
    temfile.close();@

    Now on Windows, if the NTFS filesystem has less than 5GB disk space, it displays

    @Insufficient disk space!@

    But on Linux (Ubuntu 12.10) the file is resized even if there is less space. On right click properties file size is even displayed as 5GB but it is not accounted for somehow. I can create as many 5GB files as I want due to which above code check fails.

    When I start writing into file (suppose 200MB) only then the size is accounted for 200MB but displayed as 5GB.

    Is there any solution for this? I want this to behave as it behaves on Windows.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      This is more an OS file handling problem rather than Qt's. There's not much it can do for that.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • jeremy_kJ Offline
        jeremy_kJ Offline
        jeremy_k
        wrote on last edited by
        #3

        I suspect this is happening due to sparse file handling. http://en.wikipedia.org/wiki/Sparse_file

        Off hand, I'm not sure how to prevent it other than by attempting to write.

        Asking a question about code? http://eel.is/iso-c++/testcase/

        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