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.

  • 相关阅读:
    Django数据库配置
    Django视图函数
    Django环境搭建和项目创建
    mysql5.7的安装
    在VS中手工创建一个最简单的WPF程序
    1.1 从UNIX到Linux的发展历程
    2 Class类
    1 反射
    8.6 GOF设计模式四: 策略模式… Strategy Pattern
    8.5 GOF设计模式四: 观察者模式Observer
  • 原文地址:https://www.cnblogs.com/justin_s/p/1899557.html
Copyright © 2011-2022 走看看