![]() |
CopperSpice API
1.8.1
|
Provides an interface for reading from and writing to open files. More...
Public Typedefs | |
using | FileHandleFlags = QFlags< FileHandleFlag > |
using | Permissions = QFlags< Permission > |
![]() | |
using | OpenMode = QFlags< OpenModeFlag > |
Public Types | |
enum | FileError |
enum | FileHandleFlag |
enum | MemoryMapFlags |
enum | Permission |
![]() | |
enum | OpenModeFlag |
Public Methods | |
~QFileDevice () | |
bool | atEnd () const override |
void | close () override |
FileError | error () const |
virtual QString | fileName () const |
bool | flush () |
int | handle () const |
bool | isSequential () const override |
uchar * | map (qint64 offset, qint64 size, MemoryMapFlags flags=NoOptions) |
virtual Permissions | permissions () const |
qint64 | pos () const override |
virtual bool | resize (qint64 size) |
bool | seek (qint64 pos) override |
virtual bool | setPermissions (Permissions permissionSpec) |
qint64 | size () const override |
bool | unmap (uchar *address) |
void | unsetError () |
![]() | |
QIODevice () | |
QIODevice (QObject *parent) | |
virtual | ~QIODevice () |
virtual qint64 | bytesAvailable () const |
virtual qint64 | bytesToWrite () const |
virtual bool | canReadLine () const |
QString | errorString () const |
bool | getChar (char *c) |
bool | isOpen () const |
bool | isReadable () const |
bool | isTextModeEnabled () const |
bool | isWritable () const |
virtual bool | open (OpenMode mode) |
OpenMode | openMode () const |
qint64 | peek (char *data, qint64 maxSize) |
QByteArray | peek (qint64 maxSize) |
bool | putChar (char c) |
qint64 | read (char *data, qint64 maxSize) |
QByteArray | read (qint64 maxSize) |
QByteArray | readAll () |
qint64 | readLine (char *data, qint64 maxSize) |
QByteArray | readLine (qint64 maxSize=0) |
virtual bool | reset () |
void | setTextModeEnabled (bool enabled) |
void | ungetChar (char c) |
virtual bool | waitForBytesWritten (int msecs) |
virtual bool | waitForReadyRead (int msecs) |
qint64 | write (const char *data) |
qint64 | write (const char *data, qint64 maxSize) |
qint64 | write (const QByteArray &data) |
![]() | |
QObject (QObject *parent=nullptr) | |
~QObject () | |
bool | blockSignals (bool block) |
const QList< QObject * > & | children () const |
bool | connect (const QObject *sender, const QString &signalMethod, const QString &location, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection) |
bool | connect (const QObject *sender, const QString &signalMethod, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection) |
bool | disconnect (const QObject *receiver, const QString &slotMethod=QString ()) const |
bool | disconnect (const QString &signalMethod, const QString &location, const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const |
bool | disconnect (const QString &signalMethod=QString (), const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const |
void | dumpObjectInfo () |
void | dumpObjectTree () |
QList< QString > | dynamicPropertyNames () const |
virtual bool | event (QEvent *event) |
virtual bool | eventFilter (QObject *watched, QEvent *event) |
template<typename T > | |
T | findChild (const QString &childName=QString ()) const |
template<class T > | |
QList< T > | findChildren (const QRegularExpression ®Exp, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
template<class T > | |
QList< T > | findChildren (const QString &childName=QString (), Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
bool | inherits (const QString &className) const |
void | installEventFilter (QObject *filterObj) |
bool | isWidgetType () const |
bool | isWindowType () const |
void | killTimer (int id) |
const QMetaObject * | metaObject () const |
void | moveToThread (QThread *targetThread) |
QString | objectName () const |
QObject * | parent () const |
template<class T = QVariant> | |
T | property (const QString &name) const |
void | removeEventFilter (QObject *obj) |
void | setObjectName (const QString &name) |
void | setParent (QObject *parent) |
bool | setProperty (const QString &name, const QVariant &value) |
bool | signalsBlocked () const |
int | startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer) |
QThread * | thread () const |
Protected Methods | |
qint64 | readData (char *data, qint64 maxSize) override |
qint64 | readLineData (char *data, qint64 maxSize) override |
qint64 | writeData (const char *data, qint64 maxSize) override |
![]() | |
void | setErrorString (const QString &errorString) |
void | setOpenMode (OpenMode openMode) |
![]() | |
virtual void | childEvent (QChildEvent *event) |
virtual void | connectNotify (const QMetaMethod &signalMethod) const |
virtual void | customEvent (QEvent *event) |
virtual void | disconnectNotify (const QMetaMethod &signalMethod) const |
bool | isSignalConnected (const QMetaMethod &signalMethod) const |
int | receivers (const QString &signal) const |
QObject * | sender () const |
int | senderSignalIndex () const |
virtual void | timerEvent (QTimerEvent *event) |
Additional Inherited Members | |
![]() | |
void | aboutToClose () |
void | bytesWritten (qint64 bytes) |
void | readChannelFinished () |
void | readyRead () |
![]() | |
void | destroyed (QObject *obj=nullptr) |
void | objectNameChanged (const QString &objectName) |
![]() | |
void | deleteLater () |
![]() | |
static bool | connect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod, Qt::ConnectionType type=Qt::AutoConnection) |
static bool | connect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection, const QString &location=QString ()) |
static bool | connect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection) |
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn > | |
static bool | connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...), Qt::ConnectionType type=Qt::AutoConnection) |
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T > | |
static bool | connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotLambda, Qt::ConnectionType type=Qt::AutoConnection) |
static bool | disconnect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod) |
static bool | disconnect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod) |
static bool | disconnect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod) |
static bool | disconnect (const QObject *sender, std::nullptr_t, const QObject *receiver, std::nullptr_t) |
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn > | |
static bool | disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...)) |
template<class Sender , class SignalClass , class... SignalArgs, class Receiver > | |
static bool | disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, std::nullptr_t slotMethod=nullptr) |
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T > | |
static bool | disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotMethod) |
static QMetaObject & | staticMetaObject () |
static QString | tr (const char *text, const char *comment=nullptr, std::optional< int > numArg=std::optional< int >()) |
![]() | |
objectName | |
![]() | |
T | qobject_cast (QObject *object) |
QObjectList | |
The QFileDevice class provides an interface for reading from and writing to open files.
QFileDevice is the base class for I/O devices that can read and write text and binary files and resources. QFile offers the main functionality, QFileDevice serves as a base class for sharing functionality with other file devices such as QTemporaryFile, by providing all the operations that can be done on files that have been opened by QFile or QTemporaryFile.
Typedef for QFlags<FileHandleFlag>. Refer to QFileDevice::FileHandleFlag for documentation.
Typedef for QFlags<Permission>. Refer to QFileDevice::Permissions for documentation.
This enum describes the errors that may be returned by error().
Constant | Value | Description |
---|---|---|
QFileDevice::NoError | 0 | No error occurred. |
QFileDevice::ReadError | 1 | Error occurred when reading from the file. |
QFileDevice::WriteError | 2 | Error occurred when writing to the file. |
QFileDevice::FatalError | 3 | Fatal error occurred. |
QFileDevice::ResourceError | 4 | Out of resources (e.g., too many open files, out of memory, etc.) |
QFileDevice::OpenError | 5 | File could not be opened. |
QFileDevice::AbortError | 6 | Operation was aborted. |
QFileDevice::TimeOutError | 7 | Timeout occurred. |
QFileDevice::UnspecifiedError | 8 | Unspecified error occurred. |
QFileDevice::RemoveError | 9 | File could not be removed. |
QFileDevice::RenameError | 10 | File could not be renamed. |
QFileDevice::PositionError | 11 | Position in the file could not be changed. |
QFileDevice::ResizeError | 12 | File could not be resized. |
QFileDevice::PermissionsError | 13 | File could not be accessed. |
QFileDevice::CopyError | 14 | File could not be copied. |
This enum is used when opening a file to specify additional options which only apply to files and not to a generic QIODevice.
Constant | Value | Description |
---|---|---|
QFileDevice::DontCloseHandle | 0 | If not explicitly closed, the underlying file handle is left open when the QFile object is destroyed. |
QFileDevice::AutoCloseHandle | 0x0001 | The file handle passed into open() should be closed by close(), the default behavior is that close just flushes the file and the application is responsible for closing the file handle. When opening a file by name, this flag is ignored as CopeprSpice always owns the file handle and must close it. |
This enum describes special options that may be used by the map() method.
Constant | Value | Description |
---|---|---|
QFileDevice::NoOptions | 0 | No options. |
This enum is used by the permission() function to report the permissions and ownership of a file. The values may be OR-ed together to test multiple permissions and ownership values.
Constant | Value | Description |
---|---|---|
QFileDevice::ReadOwner | 0x4000 | Readable by the owner of the file. |
QFileDevice::WriteOwner | 0x2000 | Writable by the owner of the file. |
QFileDevice::ExeOwner | 0x1000 | Executable by the owner of the file. |
QFileDevice::ReadUser | 0x0400 | Readable by the user. |
QFileDevice::WriteUser | 0x0200 | Writable by the user. |
QFileDevice::ExeUser | 0x0100 | Executable by the user. |
QFileDevice::ReadGroup | 0x0040 | Readable by the group. |
QFileDevice::WriteGroup | 0x0020 | Writable by the group. |
QFileDevice::ExeGroup | 0x0010 | Executable by the group. |
QFileDevice::ReadOther | 0x0004 | Readable by anyone. |
QFileDevice::WriteOther | 0x0002 | Writable by anyone. |
QFileDevice::ExeOther | 0x0001 | Executable by anyone. |
Because of differences in the platforms supported by CopperSpice the semantics of ReadUser, WriteUser and ExeUser are platform dependent.
On Unix, the rights of the owner of the file are returned and on Windows the rights of the current user are returned. On NTFS file systems ownership and permissions checking is disabled by default for performance reasons. To enable it include the following line.
Permission checking is then turned on and off by incrementing and decrementing qt_ntfs_permission_lookup
by 1.
QFileDevice::~QFileDevice | ( | ) |
Destroys the file device, closing it if necessary.
|
overridevirtual |
Returns true
if the end of the file has been reached, otherwise returns false.
For regular empty files on Unix (e.g. those in /proc
), this function returns true
, since the file system reports that the size of such a file is 0. Therefore, you should not depend on atEnd() when reading data from such a file, but rather call read() until no more data can be read.
Reimplemented from QIODevice::atEnd()
|
overridevirtual |
Calls QFileDevice::flush() and closes the file. Errors from flush are ignored.
Reimplemented from QIODevice::close()
FileError QFileDevice::error | ( | ) | const |
Returns the file error status.
The I/O device status returns an error code. For example, if open() returns false
, or a read/write operation returns -1, this function can be called to find out the reason why the operation failed.
|
virtual |
Returns the name of the file. The default implementation in QFileDevice returns a null string.
Reimplemented in QTemporaryFile::fileName(), QSaveFile::fileName(), QFile::fileName()
bool QFileDevice::flush | ( | ) |
Flushes any buffered data to the file. Returns true
if successful, otherwise returns false
.
int QFileDevice::handle | ( | ) | const |
Returns the file handle of the file. This is a small positive integer, suitable for use with C library functions such as fdopen() and fcntl(). If the file is not open, or there is an error, handle() returns -1.
On systems that use file descriptors for sockets (i.e. Unix systems, but not Windows) the handle can be used with QSocketNotifier as well.
|
overridevirtual |
Returns true
if the file can only be manipulated sequentially, otherwise returns false
. Most files support random-access, but some special files may not.
Reimplemented from QIODevice::isSequential()
uchar * QFileDevice::map | ( | qint64 | offset, |
qint64 | size, | ||
MemoryMapFlags | flags = NoOptions |
||
) |
Maps size bytes of the file into memory starting at offset. Returns a pointer to the memory or a nullptr if there is an error.
A file should be open for a map to succeed but the file does not need to stay open after the memory has been mapped. When the QFile is destroyed or a new file is opened with this object, any maps that have not been unmapped will automatically be unmapped. Any mapping options can be passed through flags.
|
virtual |
Returns the complete OR-ed together combination of QFile::Permission for the file.
Reimplemented in QFile::permissions()
|
overridevirtual |
Reimplemented from QIODevice::pos()
Implements QIODevice::readData()
Reimplemented from QIODevice::readLineData()
|
virtual |
Sets the file size (in bytes) size. Returns true
if the file if the resize succeeds,false otherwise. If size is larger than the file currently is the new bytes will be set to 0, if size is smaller the file is simply truncated.
Reimplemented in QFile::resize()
|
overridevirtual |
For random-access devices, this method sets the current position to pos returning true on success, or false if an error occurred. For sequential devices, the default behavior is to do nothing and return false.
Seeking beyond the end of a file: If the position is beyond the end of a file, then seek() shall not immediately extend the file. If a write is performed at this position, then the file shall be extended. The content of the file between the previous end of file and the newly written data is UNDEFINED and varies between platforms and file systems.
Reimplemented from QIODevice::seek()
|
virtual |
Sets the permissions for the file to the permissionSpec specified. Returns true
if successful, or false if the permissions can not be modified.
Reimplemented in QFile::setPermissions()
|
overridevirtual |
Returns the size of the file. For regular empty files on Unix (e.g. those in /proc
), this function returns 0; the contents of such a file are generated on demand in response to you calling read().
Reimplemented from QIODevice::size()
bool QFileDevice::unmap | ( | uchar * | address | ) |
Unmaps the memory address. Returns true
if the unmap succeeds, false otherwise.
void QFileDevice::unsetError | ( | ) |
Sets the file error to QFileDevice::NoError.
Implements QIODevice::writeData()
Reimplemented in QSaveFile::writeData()