Results 1 to 2 of 2

Thread: QTextStream to open file once but read multiple times

  1. #1
    Join Date
    Aug 2009
    Posts
    122
    Thanks
    74
    Qt products
    Qt4
    Platforms
    Windows

    Question QTextStream to open file once but read multiple times

    Hi,

    I'd like to open file once but read it several times from start to end. Do you need a new QTextStream for every read (as shown below), or is it possible to reset the the stream? I have tried flush() and reset() but they won't do it.

    Qt Code:
    1. char mystring[100]; char mystring2[100];
    2. QFile infile(""myfile.txt"); if(!infile.open(QIODevice::ReadOnly | QIODevice::Text)) {exit(1);}
    3.  
    4. QTextStream in_stream(&infile);
    5. QTextStream in_stream2(&infile);
    6. in_stream >> mystring;
    7. in_stream2 >> mysting2;
    8.  
    9. infile.close();
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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: QTextStream to open file once but read multiple times

    Qt Code:
    1. in_stream.seek(0)
    To copy to clipboard, switch view to plain text mode 
    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. The following 2 users say thank you to wysota for this useful post:

    alizadeh91 (7th April 2013), timmu (3rd January 2012)

Similar Threads

  1. Can I call setRange multiple times for QProgressBar ?
    By elizabeth.h1 in forum Qt Programming
    Replies: 2
    Last Post: 30th April 2010, 07:18
  2. Replies: 3
    Last Post: 3rd April 2010, 20:35
  3. Contex menu appear multiple times
    By kubas in forum Qt Programming
    Replies: 2
    Last Post: 7th September 2009, 14:55
  4. Replies: 5
    Last Post: 27th May 2009, 12:49
  5. How to open a file in Read Write mode
    By merry in forum Qt Programming
    Replies: 13
    Last Post: 16th November 2007, 14:40

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.