?? qiodevice.cpp
字號:
if (!sequential) { d->pos += written; d->devicePos += written; } if (!d->buffer.isEmpty() && !sequential) d->buffer.skip(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);#if defined QIODEVICE_DEBUG printf("%p QIODevice::ungetChar(0x%hhx '%c')\n", this, c, isprint(c) ? c : '?');#endif d->buffer.ungetChar(c); if (!d->isSequential()) --d->pos;}/*! \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 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 + -