QTextStream & QString 配合
把QString视为一Stream使用。
QTextStream的相关函数
QTextStream ( QString * string, QIODevice::OpenMode openMode = QIODevice::ReadWrite )
void setString ( QString * string, QIODevice::OpenMode openMode = QIODevice::ReadWrite )
bool QTextStream::atEnd () const
Returns true if there is no more data to be read from the QTextStream; otherwise returns false. This is similar to, but not the same as calling QIODevice::atEnd(), as QTextStream also takes into account its internal Unicode buffer.
qint64 QTextStream::pos () const
Returns the device position corresponding to the current position of the stream, or -1 if an error occurs (e.g., if there is no device or string, or if there's a device error).
Because QTextStream is buffered, this function may have to seek the device to reconstruct a valid device position. This operation can be expensive, so you may want to avoid calling this function in a tight loop.
bool QTextStream::seek ( qint64 pos )
Seeks to the position pos in the device. Returns true on success; otherwise returns false.
Status QTextStream::status () const
Returns the status of the text stream.
QTextStream::Ok
0
The text stream is operating normally.
QTextStream::ReadPastEnd
1
The text stream has read past the end of the data in the underlying device.
QTextStream::ReadCorruptData
2
The text stream has read corrupt data.
QString的相关函数
bool QString::isEmpty () const
Returns true if the string has no characters; otherwise returns false.
Example:
QString().isEmpty(); // returns true QString("").isEmpty(); // returns true QString("x").isEmpty(); // returns false QString("abc").isEmpty(); // returns false
bool QString::isNull () const
Returns true if this string is null; otherwise returns false.
Example:
QString().isNull(); // returns true QString("").isNull(); // returns false QString("abc").isNull(); // returns false
Qt makes a distinction between null strings and empty strings for historical reasons. For most applications, what matters is whether or not a string contains any data, and this can be determined using the isEmpty() function.