Results 1 to 15 of 15

Thread: Reading and rereading a file with QXmlStreamReader

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Reading and rereading a file with QXmlStreamReader

    Why reset the file at all? Can't you continue reading from the place where you stopped?
    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.


  2. #2
    Join Date
    Jun 2006
    Location
    Sweden
    Posts
    99
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    11
    Thanked 3 Times in 3 Posts

    Default Re: Reading and rereading a file with QXmlStreamReader

    Quote Originally Posted by wysota View Post
    Why reset the file at all? Can't you continue reading from the place where you stopped?
    I'm not sure i can since i get the "unexpected end of file"-error when i don't reset. The same is true even if i reset the file or close and reopen it. The only way around this i've found is to create a new streamReader-derived object AND reset the QIODevice:

    Qt Code:
    1. QFile file(fileName);
    2. file.open(QFile::ReadOnly | QFile::Text);
    3.  
    4. Parser typeCheck; // type checker!
    5. FileType type = typeCheck.getType(&file);
    6. file.reset();
    7. if (type == TypeA){
    8. Parser reader; // actual reading of the file
    9. if (!reader.read(&file)){
    10. cout << "uh oh." << endl;
    11. }
    12. }else{
    13. cout << "bad file type." << endl;
    14. }
    15. file.close();
    To copy to clipboard, switch view to plain text mode 

    Correct me if i'm wrong but this feels like a bug. According to the documentation, QXmlStreamReader::setDevice() is supposed to reset the reader's internal state. If that were true, then doing reset() on the IODevice and resetting the reader's device should work.

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

    Default Re: Reading and rereading a file with QXmlStreamReader

    Quote Originally Posted by TheRonin View Post
    I'm not sure i can since i get the "unexpected end of file"-error when i don't reset.
    Because you try reading from the beginning. You have to continue reading where you left off (after determining the internal type of the file).
    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.


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
  •  
Qt is a trademark of The Qt Company.