Results 1 to 8 of 8

Thread: QTextStream operator>> and error detection

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2009
    Posts
    79
    Thanks
    11
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default QTextStream operator>> and error detection

    Hi!
    I'm parsing integers from a QTextStream:

    textstream >> x >> y ;

    How can I check everything for correctness?

    Qt Code:
    1. if( ! (textstream >> x >> y))
    2. {
    3. //...
    4. }
    To copy to clipboard, switch view to plain text mode 
    does not work.

    Thanks in Advance
    Olli

  2. #2
    Join Date
    Feb 2009
    Posts
    79
    Thanks
    11
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTextStream operator>> and error detection

    <Push up>
    If you parse numbers, how do you check for errors?

    Or: do you check at all ?

  3. #3
    Join Date
    Jul 2012
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTextStream operator>> and error detection

    Bump.

    I see the latest post is from 2009, but I still don't see an answer how to do the error checking..

    in the documentation it says it will set the variable to value 0 if it cannot read proper value ("If no number was detected on the stream", to be exact), which is not very good behaviour considering 0 is among the values I have to handle with this variable...

    Do I really need to do some kind of idiotic work around?

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

    Default Re: QTextStream operator>> and error detection

    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.


  5. #5
    Join Date
    Jul 2012
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTextStream operator>> and error detection

    Thank you, I was looking at 4.7 reference apparently.

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

    Default Re: QTextStream operator>> and error detection

    This method is available since Qt 4.1: http://doc.qt.nokia.com/4.1/qtextstream.html#status
    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.


  7. #7
    Join Date
    Jul 2012
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTextStream operator>> and error detection

    Ok, I'm sorry for the mess.

    This is the page I was looking at
    http://doc.qt.nokia.com/4.7-snapshot...ml#Status-enum
    because it comes right up when googling "qtextstream reference", maybe the page has a mistake in it?
    or did you mean that the error checking when reading has been there since 4.1? because I needed the WriteFailed
    and I can't find it in 4.1...

    Anyways thanks for pointing me to the right place.

    EDIT:
    I tried with both
    Qt Code:
    1. int value;
    2. stream >> value;
    3. if(!(stream.status() == QTextStream::ReadCorruptData))
    To copy to clipboard, switch view to plain text mode 
    and
    Qt Code:
    1. int value;
    2. stream >> value;
    3. if(!(stream.status() == QTextStream::WriteFailed))
    To copy to clipboard, switch view to plain text mode 
    and both result in behaviour I want when something else than integer comes from the stream.. what is the difference between these 2 statuses?
    Last edited by Acce; 27th July 2012 at 11:25.

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

    Default Re: QTextStream operator>> and error detection

    Quote Originally Posted by Acce View Post
    Ok, I'm sorry for the mess.

    This is the page I was looking at
    http://doc.qt.nokia.com/4.7-snapshot...ml#Status-enum
    because it comes right up when googling "qtextstream reference", maybe the page has a mistake in it?
    What mistake? You are looking at the reference of an enum, not the method. At the end of the docs for the enum there is "See also status()" with a link to the method docs.

    what is the difference between these 2 statuses?
    I would guess that one is for read access and the other for write access.
    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.