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. [SOLVED] QFile - delete file content
Qt 6.11 is out! See what's new in the release blog

[SOLVED] QFile - delete file content

Scheduled Pinned Locked Moved General and Desktop
5 Posts 4 Posters 8.1k Views 1 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.
  • M Offline
    M Offline
    maccros
    wrote on last edited by
    #1

    Hi there.
    How can i delete/overwrite in a text file opened by QFile the content?

    I need to read -> edit-> write back.

    @
    QString text;

    dok->open(QIODevice::ReadWrite | QIODevice::Text));
    text = QString().fromLatin1(dok->readAll());

    // do something

    write(text.toLatin1()); // <-- This Function appends...?
    @

    Thanx

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      If you want to overwrite the content of the file after reading you need to write from the start of the file using e.g. seek(0)

      Hope it helps

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • JKSHJ Offline
        JKSHJ Offline
        JKSH
        Moderators
        wrote on last edited by
        #3

        Hi, and welcome to the Qt Dev Net!

        Qt has comprehensive documentation -- if you search it, you'll find things quite easily.

        See http://qt-project.org/doc/qt-5/qfile.html#remove for removing a file (note that you will need to re-create the file)

        Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

        1 Reply Last reply
        0
        • M Offline
          M Offline
          maccros
          wrote on last edited by
          #4

          Best thanks for your support! The solution in my case was @dok->resize(0)@

          1 Reply Last reply
          0
          • JeroentjehomeJ Offline
            JeroentjehomeJ Offline
            Jeroentjehome
            wrote on last edited by
            #5

            If this topic is solved, please place [SOLVED] in front of your first post! Thx

            Greetz, Jeroen

            1 Reply Last reply
            0

            • Login

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