Results 1 to 2 of 2

Thread: Does seeking past the end of a file and writing generate defined behavior?

  1. #1
    Join Date
    Nov 2009
    Posts
    31
    Thanks
    5

    Default Does seeking past the end of a file and writing generate defined behavior?

    I'm thinking about using QFile and the functions it inherits from QIODevice, seek and write.

    I will be receiving data for the file over a network connection, and the data is not guaranteed to come in the proper order, but will come with the offset in the file from which to start writing.

    When I first use QFile to create a new file, it is zero bytes. If I then seek to 1024 and write 512 of data, my file should now be 1536 bytes long.

    Is this proper usage of seek and write?
    Is it defined what will be in the QFile from 0-1024 (i.e. will it reliably 0 those parts)?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Does seeking past the end of a file and writing generate defined behavior?

    Quote Originally Posted by manekineko View Post
    Is this proper usage of seek and write?
    If the filesystem handles sparse files (most do, at least Unix ones) then yes. For other filesystems you'll probably get an error.

    Is it defined what will be in the QFile from 0-1024 (i.e. will it reliably 0 those parts)?
    If the filesystem handles sparse files, those missing chunks will be filled with virtual zeroes. By virtual I mean they won't take space on your disk. For filesystems without support for sparse files should you not get an error while trying to seek past the end of the file, you will probably get a proper file with junk inside skipped blocks.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 10
    Last Post: 6th April 2011, 10:05
  2. how to generate sis file with qt
    By fareenafatima in forum Newbie
    Replies: 2
    Last Post: 27th February 2011, 18:53
  3. Add tab (QtabWidget defined in UI file)
    By sang in forum Qt Programming
    Replies: 3
    Last Post: 24th August 2010, 15:36
  4. how to generate a PDF file with qt?
    By ghnie in forum Qt Programming
    Replies: 1
    Last Post: 25th March 2010, 07:23
  5. how can i generate .cpp file in QT 4.3.0
    By gamitkumar in forum General Programming
    Replies: 4
    Last Post: 3rd September 2007, 22:23

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.