Results 1 to 7 of 7

Thread: read from file two lines

  1. #1
    Join Date
    Aug 2009
    Posts
    38
    Thanks
    3

    Default read from file two lines

    Hi,

    I try to read from file two lines, and each line is allocated to a QString. I know how read the file line by line but not two lines at the same time.
    It's possible?Could you help me?

    Many thanks and sorry for my english!

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: read from file two lines

    Hmmm... is this question serious? You know how to read one line but you don't know how to read two lines? Did you try reading one line and then reading another line again? This should give you a total of how many lines read?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Aug 2009
    Posts
    38
    Thanks
    3

    Default Re: read from file two lines

    Quote Originally Posted by wysota View Post
    Hmmm... is this question serious? You know how to read one line but you don't know how to read two lines? Did you try reading one line and then reading another line again? This should give you a total of how many lines read?
    Sorry there are a lot of hours programming jejeje;
    Many thanks!

  4. #4
    Join Date
    Oct 2007
    Location
    Grenoble, France
    Posts
    80
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: read from file two lines

    I try to read from file two lines, and each line is allocated to a QString. I know how read the file line by line but not two lines at the same time.
    It's possible?Could you help me?
    I think you have to run a level 3 diagnostic
    You have to run a level 3 diagnostic.

    Ashes to ashes, Qt to Qt ( wysota )

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: read from file two lines

    Quote Originally Posted by calhal View Post
    I think you have to run a level 3 diagnostic
    Make it so, number one!
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Aug 2009
    Posts
    38
    Thanks
    3

    Default Re: read from file two lines

    Sorry I think that I don't explain very well.

    Imagine that I have a file like this:

    2004
    2008
    2010
    2013
    ....

    I read this file line by line. I must do:

    read first_line
    If first_line > 2005 then
    read second_line
    if second_line > 2006 then
    ....
    ...

    Everything it's ok but when I read the second line, when the program goes to the begining, the code reads next line (that is the third line), and I would like that the program reads the second line and so on.

    I hope you can understand me :-(

  7. #7
    Join Date
    Oct 2007
    Location
    Grenoble, France
    Posts
    80
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: read from file two lines

    Could you explain what exactly this program is supposed to do?

    Maybe it would be better if you read whole file at once like this:
    Qt Code:
    1. QStringList slist = QString(file.readAll()).split("\n");
    To copy to clipboard, switch view to plain text mode 
    And then you can access each line very easily.

    Anyway I'm not sure what do you want to achieve.
    You have to run a level 3 diagnostic.

    Ashes to ashes, Qt to Qt ( wysota )

Similar Threads

  1. read file from end to beginning..
    By soul_rebel in forum Qt Programming
    Replies: 11
    Last Post: 4th June 2012, 01:20
  2. How to read line number in a text file
    By grsandeep85 in forum Qt Programming
    Replies: 7
    Last Post: 31st July 2009, 09:09
  3. Read binary from file
    By weldpua2008 in forum Newbie
    Replies: 2
    Last Post: 3rd April 2009, 23:50
  4. QFile can't read a file
    By Raccoon29 in forum Qt Programming
    Replies: 3
    Last Post: 11th February 2009, 20:24
  5. Read delimited Lines in a file
    By mourad in forum Newbie
    Replies: 1
    Last Post: 19th April 2008, 09:18

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.