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. Seek files using format
Forum Update on Monday, May 27th 2025

Seek files using format

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 5 Posters 2.0k Views
  • 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.
  • RIVOPICOR Offline
    RIVOPICOR Offline
    RIVOPICO
    wrote on last edited by A Former User
    #1

    Hi, it is possible to seek files using a format. When i say seek i'm refering to this:
    http://doc.qt.io/qt-4.8/qfile.html#seek

    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!

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      Can you explain better what you mean by "format"

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        2
        • RIVOPICOR Offline
          RIVOPICOR Offline
          RIVOPICO
          wrote on last edited by RIVOPICO
          #4

          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!

          1 Reply Last reply
          0
          • VRoninV Offline
            VRoninV Offline
            VRonin
            wrote on last edited by
            #5

            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

            "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
            ~Napoleon Bonaparte

            On a crusade to banish setIndexWidget() from the holy land of Qt

            1 Reply Last reply
            1
            • sneubertS Offline
              sneubertS Offline
              sneubert
              wrote on last edited by
              #6

              Maybe we get you wrong, are you looking for something like QDir::entryList to search for files having specific extentions?
              http://doc.qt.io/qt-5/qdir.html#entryList

              1 Reply Last reply
              2
              • mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #7

                Hi
                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.

                1 Reply Last reply
                4

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved