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. Input from existing text file
Forum Updated to NodeBB v4.3 + New Features

Input from existing text file

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 2.2k 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.
  • A Offline
    A Offline
    ahmed kato
    wrote on last edited by
    #1

    if i have a text file with some data and i need to read it...how could i do that using QFile or other Q library...and if i would like too add some line how could i do that without deleting old data???thx =)

    Ahmed Kato
    Computer & communications student
    Intern and MSP at Microsoft

    1 Reply Last reply
    0
    • C Offline
      C Offline
      cincirin
      wrote on last edited by
      #2

      You can "read files directly":http://doc.qt.nokia.com/4.7/qfile.html#reading-files-directly or "use stream to read files":http://doc.qt.nokia.com/4.7/qfile.html#using-streams-to-read-files

      If you don't use QIODevice::Truncate flag, the file is opened without losing data.
      Also look at "text stream description":http://doc.qt.nokia.com/4.7/qtextstream.html#details for writing text files examples.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andre
        wrote on last edited by
        #3

        As always: it depends. Is your file very long? In that case, you may want to read it piece by piece using QTextStream. If it is not too big, you can read it in one go, but I would still use QTextStream (it takes care of some potential issues for you, like line endings).

        For appending data (that is: adding at the end), you can open a file in Append mode. See QFile documentation for how to do that. Then you can add to the file. You can not insert in a file without rewriting it.

        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