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

📄 qiodevice.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 4 页
字号:
}/*! \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()*/bool QIODevice::putChar(char c){    return d_func()->putCharHelper(c);}/*!    \internal*/bool QIODevicePrivate::putCharHelper(char c){    return q_func()->write(&c, 1) == 1;}/*! \fn bool QIODevice::getChar(char *c)    Reads one character from the device and stores it in \a c. If \a c    is 0, the character is discarded. Returns true on success;    otherwise returns false.    \sa read() putChar() ungetChar()*/bool QIODevice::getChar(char *c){    Q_D(QIODevice);    const OpenMode openMode = d->openMode;    if (!(openMode & ReadOnly)) {        if (openMode == NotOpen)            qWarning("QIODevice::getChar: Closed device");        else            qWarning("QIODevice::getChar: WriteOnly device");        return false;    }    // Shortcut for QIODevice::read(c, 1)    QRingBuffer *buffer = &d->buffer;    const int chint = buffer->getChar();    if (chint != -1) {        char ch = char(uchar(chint));        if ((openMode & Text) && ch == '\r') {            buffer->ungetChar(ch);        } else {            if (c)                *c = ch;            if (!d->isSequential())                ++d->pos;            return true;        }    }    // Fall back to read().    char ch;    if (read(&ch, 1) == 1) {        if (c)            *c = ch;        return true;    }    return false;}/*!    \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 readBytes = read(data, maxSize);    int i = readBytes;    while (i > 0)        ungetChar(data[i-- - 1]);    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){    QByteArray result = read(maxSize);    int i = result.size();    const char *data = result.constData();    while (i > 0)        ungetChar(data[i-- - 1]);    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.    Reimplement this function to provide a blocking API for a custom    device. The default implementation does nothing, and returns false.    \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.    Reimplement this function to provide a blocking API for a custom    device. The default implementation does nothing, and returns false.    \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{    Q_D(const QIODevice);    if (d->errorString.isEmpty()) {#ifdef QT_NO_QOBJECT        return QLatin1String(QT_TRANSLATE_NOOP(QIODevice, "Unknown error"));#else        return tr("Unknown error");#endif    }    return d->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 << QLatin1String("NotOpen");    } else {        if (modes & QIODevice::ReadOnly)            modeList << QLatin1String("ReadOnly");        if (modes & QIODevice::WriteOnly)            modeList << QLatin1String("WriteOnly");        if (modes & QIODevice::Append)            modeList << QLatin1String("Append");        if (modes & QIODevice::Truncate)            modeList << QLatin1String("Truncate");        if (modes & QIODevice::Text)            modeList << QLatin1String("Text");        if (modes & QIODevice::Unbuffered)            modeList << QLatin1String("Unbuffered");    }    qSort(modeList);    debug << modeList.join(QLatin1String("|"));    debug << ")";    return debug;}#endif

⌨️ 快捷键说明

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