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. QFile write to specific line
Forum Updated to NodeBB v4.3 + New Features

QFile write to specific line

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 4 Posters 745 Views 2 Watching
  • 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.
  • S Offline
    S Offline
    Sucharek
    wrote on last edited by
    #1

    Hi, I want to know how to write to a specific line in a file using QFile.

    J.HilkJ 1 Reply Last reply
    0
    • M Offline
      M Offline
      mpergand
      wrote on last edited by mpergand
      #2

      In the first place I would say you can't (if you want to add something in the middle of the file)
      unless you explain more what you want to do.

      1 Reply Last reply
      2
      • S Sucharek

        Hi, I want to know how to write to a specific line in a file using QFile.

        J.HilkJ Offline
        J.HilkJ Offline
        J.Hilk
        Moderators
        wrote on last edited by
        #3

        @Sucharek you can't, and thats universal, you can only write the whole file, or seek to a specific point and overwrite everything after it.

        Therefore inserting a line of text, technically not possible.
        But you could get the effect.


        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        S 1 Reply Last reply
        3
        • S Offline
          S Offline
          Sucharek
          wrote on last edited by
          #4
          This post is deleted!
          1 Reply Last reply
          0
          • J.HilkJ J.Hilk

            @Sucharek you can't, and thats universal, you can only write the whole file, or seek to a specific point and overwrite everything after it.

            Therefore inserting a line of text, technically not possible.
            But you could get the effect.

            S Offline
            S Offline
            Sucharek
            wrote on last edited by
            #5

            @J-Hilk what specific point?
            Like this: [stuff] ?
            If thats possible, then that would work for me.

            jsulmJ 1 Reply Last reply
            0
            • S Sucharek

              @J-Hilk what specific point?
              Like this: [stuff] ?
              If thats possible, then that would work for me.

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @Sucharek said in QFile write to specific line:

              what specific point?

              Specific position in the file where next read/write operation will work
              https://doc.qt.io/qt-5/qfiledevice.html#seek
              But, as @J-Hilk wrote, you will overwrite what is at this position, not insert.
              If you want to insert something you need to write the old content at the location where you're inserting after the inserted data.

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              3

              • Login

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