Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Qt file resize behaves weirdly in Linux
adnan last edited by
Here is my code snippet
if(temfile.open(QIODevice::WriteOnly) == 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.
This is more an OS file handling problem rather than Qt's. There's not much it can do for that.
jeremy_k last edited by
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.