⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qtextstream.cpp

📁 qt-x11-opensource-src-4.1.4.tar.gz源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    qDebug("QTextStream::~QTextStream()");#endif    if (!d->writeBuffer.isEmpty())        d->flushWriteBuffer();    delete d;    d_ptr = 0;}/*!    Resets QTextStream's formatting options, bringing it back to its    original constructed state. The device, string and any buffered    data is left untouched.*/void QTextStream::reset(){    Q_D(QTextStream);    d->realNumberPrecision = 6;    d->integerBase = 0;    d->fieldWidth = 0;    d->padChar = QLatin1Char(' ');    d->fieldAlignment = QTextStream::AlignRight;    d->realNumberNotation = QTextStream::SmartNotation;    d->numberFlags = 0;}/*!    Flushes any buffered data waiting to be written to the device.    If QTextStream operates on a string, this function does nothing.*/void QTextStream::flush(){    Q_D(QTextStream);    d->flushWriteBuffer();}/*!    Seeks to the position \a pos in the device. Returns true on    success; otherwise returns false.    If QTextStream operates on a string, this function does nothing    and returns false.*/bool QTextStream::seek(qint64 pos){    Q_D(QTextStream);    d->lastTokenSize = 0;    if (d->device) {        // Empty the write buffer        d->flushWriteBuffer();        if (!d->device->seek(pos))            return false;        d->readBuffer.clear();        d->readBufferOffset = 0;        d->endOfBufferState.clear();#ifndef QT_NO_TEXTCODEC        // Reset the codec converter states.        ::resetCodecConverterState(&d->readConverterState);        ::resetCodecConverterState(&d->writeConverterState);#endif        return true;    }    // string    if (d->string && pos < d->string->size()) {        d->stringOffset = int(pos);        return true;    }    return false;}/*!    Reads and discards whitespace from the stream until either a    non-space character is detected, or until atEnd() returns    true. This function is useful when reading a stream character by    character.    Whitespace characters are all characters for which    QChar::isSpace() returns true.    \sa operator>>(QChar &), operator>>(char &)*/void QTextStream::skipWhiteSpace(){    Q_D(QTextStream);    CHECK_VALID_STREAM(Q_VOID);    d->scan(0, 0, 0, QTextStreamPrivate::NotSpace);    d->consumeLastToken();}/*!    Sets the current device to \a device. If a device has already been    assigned, QTextStream will call flush() before the old device is    replaced.    \sa device(), setString()*/void QTextStream::setDevice(QIODevice *device){    Q_D(QTextStream);    flush();    if (d->deleteDevice) {#ifndef QT_NO_QOBJECT        d->deviceClosedNotifier.disconnect();#endif        delete d->device;        d->deleteDevice = false;    }    d->device = device;    d->string = 0;#ifndef QT_NO_QOBJECT    d->deviceClosedNotifier.setupDevice(this, d->device);#endif}/*!    Returns the current device associated with the QTextStream,    or 0 if no device has been assigned.    \sa setDevice(), string()*/QIODevice *QTextStream::device() const{    Q_D(const QTextStream);    return d->device;}/*!    Sets the current string to \a string, using the given \a    openMode. If a device has already been assigned, QTextStream will    call flush() before replacing it.    \sa string(), setDevice()*/void QTextStream::setString(QString *string, QIODevice::OpenMode openMode){    Q_D(QTextStream);    flush();    if (d->deleteDevice) {#ifndef QT_NO_QOBJECT        d->deviceClosedNotifier.disconnect();#endif        delete d->device;        d->deleteDevice = false;    }    d->string = string;    d->device = 0;    d->stringOpenMode = openMode;}/*!    Returns the current string assigned to the QTextStream, or 0 if no    string has been assigned.    \sa setString(), device()*/QString *QTextStream::string() const{    Q_D(const QTextStream);    return d->string;}/*!    Sets the field alignment to \a mode. When used together with    setFieldWidth(), this function allows you to generate formatted    output with text aligned to the left, to the right or center    aligned.    \sa fieldAlignment(), setFieldWidth()*/void QTextStream::setFieldAlignment(FieldAlignment mode){    Q_D(QTextStream);    d->fieldAlignment = mode;}/*!    Returns the current field alignment.    \sa setFieldAlignment(), fieldWidth()*/QTextStream::FieldAlignment QTextStream::fieldAlignment() const{    Q_D(const QTextStream);    return d->fieldAlignment;}/*!    Sets the pad character to \a ch. The default value is the ASCII    space character (' '), or QChar(0x20). This character is used to    fill in the space in fields when generating text.    Example:    \code        QString s;        QTextStream out(&s);        out.setFieldWidth(10);        out.setPadChar('-');        out << "Qt" << endl << "rocks!" << endl;    \endcode    Output:    \code        ----Qt----        --rocks!--    \endcode    \sa padChar(), setFieldWidth()*/void QTextStream::setPadChar(QChar ch){    Q_D(QTextStream);    d->padChar = ch;}/*!    Returns the current pad character.    \sa setPadChar(), setFieldWidth()*/QChar QTextStream::padChar() const{    Q_D(const QTextStream);    return d->padChar;}/*!    Sets the current field width to \a width. If \a width is 0 (the    default), the field width is equal to the length of the generated    text.    \sa fieldWidth(), setPadChar()*/void QTextStream::setFieldWidth(int width){    Q_D(QTextStream);    d->fieldWidth = width;}/*!    Returns the current field width.    \sa setFieldWidth()*/int QTextStream::fieldWidth() const{    Q_D(const QTextStream);    return d->fieldWidth;}/*!    Sets the current number flags to \a flags. \a flags is a set of    flags from the NumberFlags enum, and describes options for    formatting generated code (e.g., whether or not to always write    the base or sign of a number).    \sa numberFlags(), setIntegerBase(), setRealNumberNotation()*/void QTextStream::setNumberFlags(NumberFlags flags){    Q_D(QTextStream);    d->numberFlags = flags;}/*!    Returns the current number flags.    \sa setNumberFlags(), integerBase(), realNumberNotation()*/QTextStream::NumberFlags QTextStream::numberFlags() const{    Q_D(const QTextStream);    return d->numberFlags;}/*!    Sets the base of integers to \a base, both for reading and for    generating numbers. \a base can be either 2 (binary), 8 (octal),    10 (decimal) or 16 (hexadecimal). If \a base is 0, QTextStream    will attempt to detect the base by inspecting the data on the    stream. When generating numbers, QTextStream assumes base is 10    unless the base has been set explicitly.    \sa integerBase(), QString::number(), setNumberFlags()*/void QTextStream::setIntegerBase(int base){    Q_D(QTextStream);    d->integerBase = base;}/*!    Returns the current base of integers. 0 means that the base is    detected when reading, or 10 (decimal) when generating numbers.    \sa setIntegerBase(), QString::number(), numberFlags()*/int QTextStream::integerBase() const{    Q_D(const QTextStream);    return d->integerBase;}/*!    Sets the real number notation to \a notation (SmartNotation,    FixedNotation, ScientificNotation). When reading and generating    numbers, QTextStream uses this value to detect the formatting of    real numbers.    \sa realNumberNotation(), setRealNumberPrecision(), setNumberFlags(), setIntegerBase()*/void QTextStream::setRealNumberNotation(RealNumberNotation notation){    Q_D(QTextStream);    d->realNumberNotation = notation;}/*!    Returns the current real number notation.    \sa setRealNumberNotation(), realNumberPrecision(), numberFlags(), integerBase()*/QTextStream::RealNumberNotation QTextStream::realNumberNotation() const{    Q_D(const QTextStream);    return d->realNumberNotation;}/*!    Sets the precision of real numbers to \a precision. This value    describes the number of fraction digits QTextStream should    write when generating real numbers.    \sa realNumberPrecision(), setRealNumberNotation()*/void QTextStream::setRealNumberPrecision(int precision){    Q_D(QTextStream);    d->realNumberPrecision = precision;}/*!    Returns the current real number precision, or the number of fraction    digits QTextStream will write when generating real numbers.    \sa setRealNumberNotation(), realNumberNotation(), numberFlags(), integerBase()*/int QTextStream::realNumberPrecision() const{    Q_D(const QTextStream);    return d->realNumberPrecision;}/*!    Returns the status of the text stream.    \sa QTextStream::Status, setStatus(), resetStatus()*/QTextStream::Status QTextStream::status() const{    Q_D(const QTextStream);    return d->status;}/*!    \since 4.1    Resets the status of the text stream.    \sa QTextStream::Status, status(), setStatus()*/void QTextStream::resetStatus(){    Q_D(QTextStream);    d->status = Ok;}/*!    \since 4.1    Sets the status of the text stream to the \a status given.    \sa Status status() resetStatus()*/void QTextStream::setStatus(Status status){    Q_D(QTextStream);    if (d->status == Ok)        d->status = status;}/*!    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.*/bool QTextStream::atEnd() const{    Q_D(const QTextStream);    CHECK_VALID_STREAM(true);    if (d->string)        return d->string->size() == d->stringOffset;    return d->readBuffer.isEmpty() && d->device->atEnd();}/*!    Reads the entire content of the stream, and returns it as a    QString. Avoid this function when working on large files, as it    will consume a significant amount of memory.    Calling readLine() is better if you do not know how much data is    available.    \sa readLine()*/QString QTextStream::readAll(){    Q_D(QTextStream);    CHECK_VALID_STREAM(QString());    const QChar *readPtr;    int length;    if (!d->scan(&readPtr, &length, /* maxlen = */ 0, QTextStreamPrivate::EndOfFile))        return QString();    QString tmp = QString(readPtr, length);    d->consumeLastToken();    return tmp;}/*!    Reads one line of text from the stream, and returns it as a    QString. The maximum allowed line length is set to \a maxlen. If    the stream contains lines longer than this, then the lines will be    split after \a maxlen characters and returned in parts.    If \a maxlen is 0, the lines can be of any length. A common value    for \a maxlen is 75.    The returned line has no trailing end-of-line characters, so    calling QString::trimmed() is unnecessary.    If the stream has read to the end of the file, the returned string    will be a null string - see QString::isNull(). Empty lines are    represented by empty, but non-null strings - see QString::isEmpty().    You can also explicitly test for the end of the file using atEnd().    \sa readAll()*/QString QTextStream::readLine(qint64 maxlen){    Q_D(QTextStream);    CHECK_VALID_STREAM(QString());    const QChar *readPtr;    int length;    if (!d->scan(&readPtr, &length, int(maxlen), QTextStreamPrivate::EndOfLine))        return QString();    QString tmp = QString(readPtr, length);    d->consumeLastToken();    return tmp;}/*!    \since 4.1    Reads at most \a maxlen characters from the stream, and returns the data    read as a QString.    \sa readAll(), readLine(), QIODevice::read()*/QString QTextStream::read(qint64 maxlen){    Q_D(QTextStream);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -