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

📄 qiodevice.cpp

📁 qt-x11-opensource-src-4.1.4.tar.gz源码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
#ifdef Q_OS_WIN    if (d->openMode & Text) {        const char *endOfData = data + maxSize;        const char *startOfBlock = data;        qint64 writtenSoFar = 0;        forever {            const char *endOfBlock = startOfBlock;            while (endOfBlock < endOfData && *endOfBlock != '\n')                ++endOfBlock;            qint64 blockSize = endOfBlock - startOfBlock;            if (blockSize > 0) {                qint64 ret = writeData(startOfBlock, blockSize);                if (ret <= 0) {                    if (writtenSoFar)                        d->ungetBuffer.chop(writtenSoFar);                    return writtenSoFar ? writtenSoFar : ret;                }                writtenSoFar += ret;            }            if (endOfBlock == endOfData)                break;            qint64 ret = writeData("\r\n", 2);            if (ret <= 0) {                if (writtenSoFar)                    d->ungetBuffer.chop(writtenSoFar);                return writtenSoFar ? writtenSoFar : ret;            }            ++writtenSoFar;            startOfBlock = endOfBlock + 1;        }        if (writtenSoFar)            d->ungetBuffer.chop(writtenSoFar);        return writtenSoFar;    }#endif    qint64 written = writeData(data, maxSize);    if (written > 0 && !d->ungetBuffer.isEmpty())        d->ungetBuffer.chop(written);    return written;}/*! \fn qint64 QIODevice::write(const QByteArray &byteArray)    \overload    Writes the content of \a byteArray to the device. Returns the number of    bytes that were actually written, or -1 if an error occurred.    \sa read() writeData()*//*! \fn bool QIODevice::putChar(char c)    Writes the character \a c to the device. Returns true on success;    otherwise returns false.    \sa write() getChar() ungetChar()*//*!    Puts the character \a c back into the device, and decrements the    current position unless the position is 0. This function is    usually called to "undo" a getChar() operation, such as when    writing a backtracking parser.    If \a c was not previously read from the device, the behavior is    undefined.*/void QIODevice::ungetChar(char c){    Q_D(QIODevice);    CHECK_OPEN(write, Q_VOID);    CHECK_READABLE(read, Q_VOID);    d->ungetBuffer.append(c);    if (!isSequential()) {        qint64 curPos = pos();        if (curPos > 0) {            QByteArray tmp = d->ungetBuffer;            seek(curPos - 1);            d->ungetBuffer = tmp;        }    }}/*!    \since 4.1    Reads at most \a maxSize bytes from the device into \a data, without side    effects (i.e., if you call read() after peek(), you will get the same    data).  Returns the number of bytes read. If an error occurs, such as    when attempting to peek a device opened in WriteOnly mode, this function    returns -1.    0 is returned when no more data is available for reading.    Example:    \code        bool isExeFile(QFile *file)        {            char buf[2];            if (file->peek(buf, sizeof(buf)) == sizeof(buf))                return (buf[0] == 'M' && buf[1] == 'Z');            return false;        }    \endcode    \sa read()*/qint64 QIODevice::peek(char *data, qint64 maxSize){    qint64 oldPos = pos();    qint64 readBytes = read(data, maxSize);    if (isSequential()) {        int i = readBytes;        while (i > 0)            ungetChar(data[i-- - 1]);    } else {        seek(oldPos);    }    return readBytes;}/*!    \since 4.1    \overload    Peeks at most \a maxSize bytes from the device, returning the data peeked    as a QByteArray.    Example:    \code        bool isExeFile(QFile *file)        {            return file->peek(2) == "MZ";        }    \endcode    This function has no way of reporting errors; returning an empty    QByteArray() can mean either that no data was currently available    for peeking, or that an error occurred.    \sa read()*/QByteArray QIODevice::peek(qint64 maxSize){    qint64 oldPos = pos();    QByteArray result = read(maxSize);    if (isSequential()) {        int i = result.size();        const char *data = result.constData();        while (i > 0)            ungetChar(data[i-- - 1]);    } else {        seek(oldPos);    }    return result;}/*!    Blocks until data is available for reading and the readyRead()    signal has been emitted, or until \a msecs milliseconds have    passed. If msecs is -1, this function will not time out.    Returns true if data is available for reading; otherwise returns    false (if the operation timed out or if an error occurred).    This function can operate without an event loop. It is    useful when writing non-GUI applications and when performing    I/O operations in a non-GUI thread.    If called from within a slot connected to the readyRead() signal,    readyRead() will not be reemitted.    \warning Calling this function from the main (GUI) thread    might cause your user interface to freeze.    \sa waitForBytesWritten()*/bool QIODevice::waitForReadyRead(int msecs){    Q_UNUSED(msecs);    return false;}/*!    For buffered devices, this function waits until a payload of    buffered written data has been written to the device and the    bytesWritten() signal has been emitted, or until \a msecs    milliseconds have passed. If msecs is -1, this function will    not time out. For unbuffered devices, it returns immediately.    Returns true if a payload of data was written to the device;    otherwise returns false (i.e. if the operation timed out, or if an    error occurred).    This function can operate without an event loop. It is    useful when writing non-GUI applications and when performing    I/O operations in a non-GUI thread.    If called from within a slot connected to the bytesWritten() signal,    bytesWritten() will not be reemitted.    \warning Calling this function from the main (GUI) thread    might cause your user interface to freeze.    \sa waitForReadyRead()*/bool QIODevice::waitForBytesWritten(int msecs){    Q_UNUSED(msecs);    return false;}/*!    Sets the human readable description of the last device error that    occurred to \a str.    \sa errorString()*/void QIODevice::setErrorString(const QString &str){    d_func()->errorString = str;}/*!    Returns a human-readable description of the last device error that    occurred.    \sa setErrorString()*/QString QIODevice::errorString() const{    return d_func()->errorString;}/*!    \fn qint64 QIODevice::readData(char *data, qint64 maxSize)    Reads up to \a maxSize bytes from the device into \a data, and    returns the number of bytes read or -1 if an error occurred.    This function is called by QIODevice. Reimplement this function    when creating a subclass of QIODevice.    \sa read() readLine() writeData()*//*!    \fn qint64 QIODevice::writeData(const char *data, qint64 maxSize)    Writes up to \a maxSize bytes from \a data to the device. Returns    the number of bytes written, or -1 if an error occurred.    This function is called by QIODevice. Reimplement this function    when creating a subclass of QIODevice.    \sa read() write()*//*!    \fn QIODevice::Offset QIODevice::status() const    For device specific error handling, please refer to the    individual device documentation.    \sa qobject_cast()*//*!    \fn QIODevice::Offset QIODevice::at() const    Use pos() instead.*//*!    \fn bool QIODevice::at(Offset offset)    Use seek(\a offset) instead.*//*! \fn int QIODevice::flags() const    Use openMode() instead.*//*! \fn int QIODevice::getch()    Use getChar() instead.*//*!    \fn bool QIODevice::isAsynchronous() const    This functionality is no longer available. This function always    returns true.*//*!    \fn bool QIODevice::isBuffered() const    Use !(openMode() & QIODevice::Unbuffered) instead.*//*!    \fn bool QIODevice::isCombinedAccess() const    Use openMode() instead.*//*!    \fn bool QIODevice::isDirectAccess() const    Use !isSequential() instead.*//*!    \fn bool QIODevice::isInactive() const    Use isOpen(), isReadable(), or isWritable() instead.*//*!    \fn bool QIODevice::isRaw() const    Use openMode() instead.*//*!    \fn bool QIODevice::isSequentialAccess() const    Use isSequential() instead.*//*!    \fn bool QIODevice::isSynchronous() const    This functionality is no longer available. This function always    returns false.*//*!    \fn bool QIODevice::isTranslated() const    Use openMode() instead.*//*!    \fn bool QIODevice::mode() const    Use openMode() instead.*//*! \fn int QIODevice::putch(int ch)    Use putChar(\a ch) instead.*//*! \fn int QIODevice::ungetch(int ch)    Use ungetChar(\a ch) instead.*//*!    \fn quint64 QIODevice::readBlock(char *data, quint64 size)    Use read(\a data, \a size) instead.*//*! \fn int QIODevice::state() const    Use isOpen() instead.*//*!    \fn qint64 QIODevice::writeBlock(const char *data, quint64 size)    Use write(\a data, \a size) instead.*//*!    \fn qint64 QIODevice::writeBlock(const QByteArray &data)    Use write(\a data) instead.*/#if defined QT3_SUPPORTQIODevice::Status QIODevice::status() const{#if !defined(QT_NO_QOBJECT)    const QFile *f = qobject_cast<const QFile *>(this);    if (f) return (int) f->error();#endif    return isOpen() ? 0 /* IO_Ok */ : 8 /* IO_UnspecifiedError */;}/*!    For device specific error handling, please refer to the    individual device documentation.    \sa qobject_cast()*/void QIODevice::resetStatus(){#if !defined(QT_NO_QOBJECT)    QFile *f = qobject_cast<QFile *>(this);    if (f) f->unsetError();#endif}#endif#if !defined(QT_NO_DEBUG_STREAM)QDebug operator<<(QDebug debug, QIODevice::OpenMode modes){    debug << "OpenMode(";    QStringList modeList;    if (modes == QIODevice::NotOpen) {        modeList << "NotOpen";    } else {        if (modes & QIODevice::ReadOnly)            modeList << "ReadOnly";        if (modes & QIODevice::WriteOnly)            modeList << "WriteOnly";        if (modes & QIODevice::Append)            modeList << "Append";        if (modes & QIODevice::Truncate)            modeList << "Truncate";        if (modes & QIODevice::Text)            modeList << "Text";        if (modes & QIODevice::Unbuffered)            modeList << "Unbuffered";    }    qSort(modeList);    debug << modeList.join("|");    debug << ")";    return debug;}#endif

⌨️ 快捷键说明

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