Important: Please read the Qt Code of Conduct -

QTextStream and unget (or ungetChar)

  • Hi,

    is unget possible with QTextStream?
    How does one go about peek'ing or unget'ing stuff?

    Use-case: read either a string of a number from a steam.
    How: read a character (is >> ws >> ch) and if it is a number (i.e. isdigit(ch) == true), unget it and read into an int (is >> number)


  • Something like this might work (didn't try it)

    qint64 text_pos;
    text_pos = text_stream.pos();

    // read char

    // read number instead


Log in to reply