Text streams

Much of the data produced by computers nowadays is based on text. You can create such files using a mechanism that you already know—opening QFile to write, converting all data into strings using QString::arg(), optionally encoding strings using QTextCodec, and dumping the resulting bytes to the file by calling write. However, Qt provides a nice mechanism that does most of this automatically for you in a way similar to how the standard C++ iostream classes work. The QTextStream class operates on any QIODevice API in a stream-oriented way. You can send tokens to the stream using the << operator, where they get converted into strings, separated by spaces, encoded using a codec of your choice, and written to the underlying device. ...

Get Game Programming using Qt 5 Beginner's Guide - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.