Important: Please read the Qt Code of Conduct -

Qt file resize behaves weirdly in Linux

  • Here is my code snippet

    @QFile temfile(fileUrl);
    if( == false)
    qDebug()<<"Unable to create file!";
    if(temfile.resize(5073741824) == false) // 5GB
    qDebug()<<"Insufficient disk space!";

    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.

  • Lifetime Qt Champion


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

  • I suspect this is happening due to sparse file handling.

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

Log in to reply