Qt World Summit: Register Today!

Seek files using format

  • Hi, it is possible to seek files using a format. When i say seek i'm refering to this:

    Normally i seek files knowing the size of my data for example:

    archivoStub->seek(archivoStub->size() - 1024);

    It's only to be sure. Because if i use int i will be limited to the range of this int, For this i ask. Because maybe i can use one file to save the size of my data for example size of one qbytearray. And then seek this file only with format and then read the size of my qbytearray. thanks for all!

  • Can you explain better what you mean by "format"

  • Hi! I don't understand what you mean by "format". Anyways, if you want to read / write byte arrays etc from / to your files then you'll probably want to have a look at how to serialize / deserialize data using QDataStream.

  • when i say format i'm meaning .dat or .txt or any file with some type of extension. If it possible to seek with this extension. But not sure. I check how to serialize / deserialize data using QDataStream. will help me a lot ! thanks!

  • At the root of it all there exist only binary files, the file extensions determines a standard of how the binary file is written, see https://en.wikipedia.org/wiki/MP3#File_structure for example. at the end of the day they all are just a long string of binary data that, of course, you can seek

  • Maybe we get you wrong, are you looking for something like QDir::entryList to search for files having specific extentions?

  • Lifetime Qt Champion

    using seek can move the file pointer into a byte position in the file.
    Like 400 bytes into it.
    IF you want to use seek to go into the file at some position you must know
    how big the offset must be.
    If that is hard to know, you should create a format that suits what you need.
    One way is to have a fixed size header that has the offset values.
    You then first read the header ( maybe first 200 bytes)
    and this header has the values for the offset into the file.

Log in to reply