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 and specific line

QFile and specific line

Scheduled Pinned Locked Moved General and Desktop
5 Posts 5 Posters 11.4k 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.
  • R Offline
    R Offline
    roosaw
    wrote on last edited by
    #1

    Hi,
    How to read specific line to QString? I know how to do this with reading whole text file, but i wanna read text from specific file. I have that code:
    @
    //(..)
    file->open(QIODevice::ReadOnly | QIODevice::Text);
    QString line;
    int tab[9];
    while(!file->atEnd()){
    line = file->readLine();
    tab[i] = line.toInt();
    i++;
    }
    file->close();
    @
    ...and that's ok. It works. I have some of that from doc, but how to get to for example ... 12th line? They are all numbers.
    I guess, i have to put loop which reading file (and move pointer forward), but i don't know what condition could it be. My prevorious tryings were fails so I'm looking forward for answer...

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #2

      You gave the answer right yourselef: create a loop and read until the place you need.

      If you don't know the additional conditions, how could we know?

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • Z Offline
        Z Offline
        zester
        wrote on last edited by
        #3

        Do the text documents use some type of pre formated text, like markup?

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

          You can not only read the nth line of a text file, not unless you have additional information. One help could be every line having the same number of characters. If you know that each line has, say, 20 characters (exactly!), you can just skip to the correct position in the file.

          1 Reply Last reply
          0
          • D Offline
            D Offline
            Darryl DSouza
            wrote on last edited by
            #5

            If you want to read 'N'th line of a file with randomly generated text, you have only the option of reading line by line. If you know any character size upto that location you could probably do a relative jump.

            Darryl D'Souza

            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