zoukankan      html  css  js  c++  java
  • 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.

  • 相关阅读:
    MinGW GCC 7.1.0 2017年6月份出炉啦
    java面试题-框架篇九
    spring-AOP原理
    spring的bean管理(注解)
    23种设计模式(1)-单例模式
    SSH框架面试题集锦
    JQuery基础
    实现用户注册
    spring与hibernate的整合
    spring-IOC理解1
  • 原文地址:https://www.cnblogs.com/justin_s/p/1899557.html
Copyright © 2011-2022 走看看