[][src]Struct qt_core::QSaveFile

#[repr(C)]
pub struct QSaveFile { /* fields omitted */ }

The QSaveFile class provides an interface for safely writing to files.

C++ class: QSaveFile.

C++ documentation:

The QSaveFile class provides an interface for safely writing to files.

QSaveFile is an I/O device for writing text and binary files, without losing existing data if the writing operation fails.

While writing, the contents will be written to a temporary file, and if no error happened, commit() will move it to the final file. This ensures that no data at the final file is lost in case an error happens while writing, and no partially-written file is ever present at the final location. Always use QSaveFile when saving entire documents to disk.

QSaveFile automatically detects errors while writing, such as the full partition situation, where write() cannot write all the bytes. It will remember that an error happened, and will discard the temporary file in commit().

Much like with QFile, the file is opened with open(). Data is usually read and written using QDataStream or QTextStream, but you can also call the QIODevice-inherited functions read(), readLine(), readAll(), write().

Unlike QFile, calling close() is not allowed. commit() replaces it. If commit() was not called and the QSaveFile instance is destroyed, the temporary file is discarded.

To abort saving due to an application error, call cancelWriting(), so that even a call to commit() later on will not save.

Methods

impl QSaveFile[src]

pub unsafe fn cancel_writing(&mut self)[src]

Cancels writing the new file.

Calls C++ function: void QSaveFile::cancelWriting().

C++ documentation:

Cancels writing the new file.

If the application changes its mind while saving, it can call cancelWriting(), which sets an error code so that commit() will discard the temporary file.

Alternatively, it can simply make sure not to call commit().

Further write operations are possible after calling this method, but none of it will have any effect, the written file will be discarded.

This method has no effect when direct write fallback is used. This is the case when saving over an existing file in a readonly directory: no temporary file can be created, so the existing file is overwritten no matter what, and cancelWriting() cannot do anything about that, the contents of the existing file will be lost.

See also commit().

pub unsafe fn commit(&mut self) -> bool[src]

Commits the changes to disk, if all previous writes were successful.

Calls C++ function: bool QSaveFile::commit().

C++ documentation:

Commits the changes to disk, if all previous writes were successful.

It is mandatory to call this at the end of the saving operation, otherwise the file will be discarded.

If an error happened during writing, deletes the temporary file and returns false. Otherwise, renames it to the final fileName and returns true on success. Finally, closes the device.

See also cancelWriting().

pub unsafe fn direct_write_fallback(&self) -> bool[src]

Returns true if the fallback solution for saving files in read-only directories is enabled.

Calls C++ function: bool QSaveFile::directWriteFallback() const.

C++ documentation:

Returns true if the fallback solution for saving files in read-only directories is enabled.

See also setDirectWriteFallback().

pub unsafe fn file_name(&self) -> CppBox<QString>[src]

Reimplemented from QFileDevice::fileName().

Calls C++ function: virtual QString QSaveFile::fileName() const.

C++ documentation:

Reimplemented from QFileDevice::fileName().

Returns the name set by setFileName() or to the QSaveFile constructor.

See also setFileName().

pub unsafe fn meta_object(&self) -> Ptr<QMetaObject>[src]

Calls C++ function: virtual const QMetaObject* QSaveFile::metaObject() const.

pub unsafe fn from_q_string(
    name: impl CastInto<Ref<QString>>
) -> QBox<QSaveFile>
[src]

Constructs a new file object to represent the file with the given name.

Calls C++ function: [constructor] void QSaveFile::QSaveFile(const QString& name).

C++ documentation:

Constructs a new file object to represent the file with the given name.

pub unsafe fn from_q_object(
    parent: impl CastInto<MutPtr<QObject>>
) -> QBox<QSaveFile>
[src]

Constructs a new file object with the given parent.

Calls C++ function: [constructor] void QSaveFile::QSaveFile(QObject* parent = …).

C++ documentation:

Constructs a new file object with the given parent.

pub unsafe fn from_q_string_q_object(
    name: impl CastInto<Ref<QString>>,
    parent: impl CastInto<MutPtr<QObject>>
) -> QBox<QSaveFile>
[src]

Constructs a new file object with the given parent to represent the file with the specified name.

Calls C++ function: [constructor] void QSaveFile::QSaveFile(const QString& name, QObject* parent).

C++ documentation:

Constructs a new file object with the given parent to represent the file with the specified name.

pub unsafe fn new() -> QBox<QSaveFile>[src]

The QSaveFile class provides an interface for safely writing to files.

Calls C++ function: [constructor] void QSaveFile::QSaveFile().

C++ documentation:

The QSaveFile class provides an interface for safely writing to files.

QSaveFile is an I/O device for writing text and binary files, without losing existing data if the writing operation fails.

While writing, the contents will be written to a temporary file, and if no error happened, commit() will move it to the final file. This ensures that no data at the final file is lost in case an error happens while writing, and no partially-written file is ever present at the final location. Always use QSaveFile when saving entire documents to disk.

QSaveFile automatically detects errors while writing, such as the full partition situation, where write() cannot write all the bytes. It will remember that an error happened, and will discard the temporary file in commit().

Much like with QFile, the file is opened with open(). Data is usually read and written using QDataStream or QTextStream, but you can also call the QIODevice-inherited functions read(), readLine(), readAll(), write().

Unlike QFile, calling close() is not allowed. commit() replaces it. If commit() was not called and the QSaveFile instance is destroyed, the temporary file is discarded.

To abort saving due to an application error, call cancelWriting(), so that even a call to commit() later on will not save.

pub unsafe fn open(&mut self, flags: QFlags<OpenModeFlag>) -> bool[src]

Reimplemented from QIODevice::open().

Calls C++ function: virtual bool QSaveFile::open(QFlags<QIODevice::OpenModeFlag> flags).

C++ documentation:

Reimplemented from QIODevice::open().

Opens the file using OpenMode mode, returning true if successful; otherwise false.

Important: the mode must include QIODevice::WriteOnly. It may also have additional flags, such as QIODevice::Text and QIODevice::Unbuffered.

QIODevice::ReadWrite and QIODevice::Append are not supported at the moment.

See also QIODevice::OpenMode and setFileName().

pub unsafe fn qt_metacall(
    &mut self,
    arg1: Call,
    arg2: c_int,
    arg3: impl CastInto<MutPtr<*mut c_void>>
) -> c_int
[src]

Calls C++ function: virtual int QSaveFile::qt_metacall(QMetaObject::Call arg1, int arg2, void** arg3).

pub unsafe fn qt_metacast(
    &mut self,
    arg1: impl CastInto<Ptr<c_char>>
) -> MutPtr<c_void>
[src]

Calls C++ function: virtual void* QSaveFile::qt_metacast(const char* arg1).

pub unsafe fn set_direct_write_fallback(&mut self, enabled: bool)[src]

Allows writing over the existing file if necessary.

Calls C++ function: void QSaveFile::setDirectWriteFallback(bool enabled).

C++ documentation:

Allows writing over the existing file if necessary.

QSaveFile creates a temporary file in the same directory as the final file and atomically renames it. However this is not possible if the directory permissions do not allow creating new files. In order to preserve atomicity guarantees, open() fails when it cannot create the temporary file.

In order to allow users to edit files with write permissions in a directory with restricted permissions, call setDirectWriteFallback() with enabled set to true, and the following calls to open() will fallback to opening the existing file directly and writing into it, without the use of a temporary file. This does not have atomicity guarantees, i.e. an application crash or for instance a power failure could lead to a partially-written file on disk. It also means cancelWriting() has no effect, in such a case.

Typically, to save documents edited by the user, call setDirectWriteFallback(true), and to save application internal files (configuration files, data files, ...), keep the default setting which ensures atomicity.

See also directWriteFallback().

pub unsafe fn set_file_name(&mut self, name: impl CastInto<Ref<QString>>)[src]

Sets the name of the file. The name can have no path, a relative path, or an absolute path.

Calls C++ function: void QSaveFile::setFileName(const QString& name).

C++ documentation:

Sets the name of the file. The name can have no path, a relative path, or an absolute path.

See also QFile::setFileName() and fileName().

pub unsafe fn static_meta_object() -> Ref<QMetaObject>[src]

Returns a reference to the staticMetaObject field.

pub unsafe fn tr(
    s: impl CastInto<Ptr<c_char>>,
    c: impl CastInto<Ptr<c_char>>,
    n: c_int
) -> CppBox<QString>
[src]

Calls C++ function: static QString QSaveFile::tr(const char* s, const char* c, int n).

pub unsafe fn tr_utf8(
    s: impl CastInto<Ptr<c_char>>,
    c: impl CastInto<Ptr<c_char>>,
    n: c_int
) -> CppBox<QString>
[src]

Calls C++ function: static QString QSaveFile::trUtf8(const char* s, const char* c, int n).

Methods from Deref<Target = QFileDevice>

pub unsafe fn at_end(&self) -> bool[src]

Reimplemented from QIODevice::atEnd().

Calls C++ function: virtual bool QFileDevice::atEnd() const.

C++ documentation:

Reimplemented from QIODevice::atEnd().

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.

pub unsafe fn close(&mut self)[src]

Reimplemented from QIODevice::close().

Calls C++ function: virtual void QFileDevice::close().

C++ documentation:

Reimplemented from QIODevice::close().

Calls QFileDevice::flush() and closes the file. Errors from flush are ignored.

See also QIODevice::close().

pub unsafe fn error(&self) -> FileError[src]

Returns the file error status.

Calls C++ function: QFileDevice::FileError QFileDevice::error() const.

C++ documentation:

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.

See also unsetError().

pub unsafe fn file_name(&self) -> CppBox<QString>[src]

Returns the name of the file. The default implementation in QFileDevice returns a null string.

Calls C++ function: virtual QString QFileDevice::fileName() const.

C++ documentation:

Returns the name of the file. The default implementation in QFileDevice returns a null string.

pub unsafe fn file_time(&self, time: FileTime) -> CppBox<QDateTime>[src]

Returns the file time specified by time. If the time cannot be determined return QDateTime() (an invalid date time).

Calls C++ function: QDateTime QFileDevice::fileTime(QFileDevice::FileTime time) const.

C++ documentation:

Returns the file time specified by time. If the time cannot be determined return QDateTime() (an invalid date time).

This function was introduced in Qt 5.10.

See also setFileTime(), FileTime, and QDateTime::isValid().

This item is available if any(cpp_lib_version="5.11.3", cpp_lib_version="5.12.2", cpp_lib_version="5.13.0", cpp_lib_version="5.14.0").

pub unsafe fn flush(&mut self) -> bool[src]

Flushes any buffered data to the file. Returns true if successful; otherwise returns false.

Calls C++ function: bool QFileDevice::flush().

C++ documentation:

Flushes any buffered data to the file. Returns true if successful; otherwise returns false.

pub unsafe fn handle(&self) -> c_int[src]

Returns the file handle of the file.

Calls C++ function: int QFileDevice::handle() const.

C++ documentation:

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(). On systems that use file descriptors for sockets (i.e. Unix systems, but not Windows) the handle can be used with QSocketNotifier as well.

If the file is not open, or there is an error, handle() returns -1.

See also QSocketNotifier.

pub unsafe fn is_sequential(&self) -> bool[src]

Reimplemented from QIODevice::isSequential().

Calls C++ function: virtual bool QFileDevice::isSequential() const.

C++ documentation:

Reimplemented from QIODevice::isSequential().

Returns true if the file can only be manipulated sequentially; otherwise returns false.

Most files support random-access, but some special files may not.

See also QIODevice::isSequential().

pub unsafe fn map_3a(
    &mut self,
    offset: i64,
    size: i64,
    flags: MemoryMapFlags
) -> MutPtr<c_uchar>
[src]

Maps size bytes of the file into memory starting at offset. 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.

Calls C++ function: unsigned char* QFileDevice::map(qint64 offset, qint64 size, QFileDevice::MemoryMapFlags flags = …).

C++ documentation:

Maps size bytes of the file into memory starting at offset. 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.

The mapping will have the same open mode as the file (read and/or write), except when using MapPrivateOption, in which case it is always possible to write to the mapped memory.

Any mapping options can be passed through flags.

Returns a pointer to the memory or 0 if there is an error.

See also unmap().

pub unsafe fn map_2a(&mut self, offset: i64, size: i64) -> MutPtr<c_uchar>[src]

Maps size bytes of the file into memory starting at offset. 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.

Calls C++ function: unsigned char* QFileDevice::map(qint64 offset, qint64 size).

C++ documentation:

Maps size bytes of the file into memory starting at offset. 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.

The mapping will have the same open mode as the file (read and/or write), except when using MapPrivateOption, in which case it is always possible to write to the mapped memory.

Any mapping options can be passed through flags.

Returns a pointer to the memory or 0 if there is an error.

See also unmap().

pub unsafe fn meta_object(&self) -> Ptr<QMetaObject>[src]

Calls C++ function: virtual const QMetaObject* QFileDevice::metaObject() const.

pub unsafe fn permissions(&self) -> QFlags<Permission>[src]

Returns the complete OR-ed together combination of QFile::Permission for the file.

Calls C++ function: virtual QFlags<QFileDevice::Permission> QFileDevice::permissions() const.

C++ documentation:

Returns the complete OR-ed together combination of QFile::Permission for the file.

See also setPermissions().

pub unsafe fn pos(&self) -> i64[src]

Reimplemented from QIODevice::pos().

Calls C++ function: virtual qint64 QFileDevice::pos() const.

C++ documentation:

Reimplemented from QIODevice::pos().

pub unsafe fn qt_metacall(
    &mut self,
    arg1: Call,
    arg2: c_int,
    arg3: impl CastInto<MutPtr<*mut c_void>>
) -> c_int
[src]

Calls C++ function: virtual int QFileDevice::qt_metacall(QMetaObject::Call arg1, int arg2, void** arg3).

pub unsafe fn qt_metacast(
    &mut self,
    arg1: impl CastInto<Ptr<c_char>>
) -> MutPtr<c_void>
[src]

Calls C++ function: virtual void* QFileDevice::qt_metacast(const char* arg1).

pub unsafe fn resize(&mut self, sz: i64) -> bool[src]

Sets the file size (in bytes) sz. Returns true if the resize succeeds; false otherwise. If sz is larger than the file currently is, the new bytes will be set to 0; if sz is smaller, the file is simply truncated.

Calls C++ function: virtual bool QFileDevice::resize(qint64 sz).

C++ documentation:

Sets the file size (in bytes) sz. Returns true if the resize succeeds; false otherwise. If sz is larger than the file currently is, the new bytes will be set to 0; if sz is smaller, the file is simply truncated.

Warning: This function can fail if the file doesn't exist.

See also size().

pub unsafe fn seek(&mut self, offset: i64) -> bool[src]

Reimplemented from QIODevice::seek().

Calls C++ function: virtual bool QFileDevice::seek(qint64 offset).

C++ documentation:

Reimplemented from QIODevice::seek().

For random-access devices, this function 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() will not immediately extend the file. If a write is performed at this position, then the file will 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.

pub unsafe fn set_file_time(
    &mut self,
    new_date: impl CastInto<Ref<QDateTime>>,
    file_time: FileTime
) -> bool
[src]

Sets the file time specified by fileTime to newDate, returning true if successful; otherwise returns false.

Calls C++ function: bool QFileDevice::setFileTime(const QDateTime& newDate, QFileDevice::FileTime fileTime).

C++ documentation:

Sets the file time specified by fileTime to newDate, returning true if successful; otherwise returns false.

Note: The file must be open to use this function.

This function was introduced in Qt 5.10.

See also fileTime() and FileTime.

This item is available if any(cpp_lib_version="5.11.3", cpp_lib_version="5.12.2", cpp_lib_version="5.13.0", cpp_lib_version="5.14.0").

pub unsafe fn set_permissions(
    &mut self,
    permission_spec: QFlags<Permission>
) -> bool
[src]

Sets the permissions for the file to the permissions specified. Returns true if successful, or false if the permissions cannot be modified.

Calls C++ function: virtual bool QFileDevice::setPermissions(QFlags<QFileDevice::Permission> permissionSpec).

C++ documentation:

Sets the permissions for the file to the permissions specified. Returns true if successful, or false if the permissions cannot be modified.

Warning: This function does not manipulate ACLs, which may limit its effectiveness.

See also permissions().

pub unsafe fn size(&self) -> i64[src]

Reimplemented from QIODevice::size().

Calls C++ function: virtual qint64 QFileDevice::size() const.

C++ documentation:

Reimplemented from QIODevice::size().

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().

pub unsafe fn unmap(&mut self, address: impl CastInto<MutPtr<c_uchar>>) -> bool[src]

Unmaps the memory address.

Calls C++ function: bool QFileDevice::unmap(unsigned char* address).

C++ documentation:

Unmaps the memory address.

Returns true if the unmap succeeds; false otherwise.

See also map().

pub unsafe fn unset_error(&mut self)[src]

Sets the file's error to QFileDevice::NoError.

Calls C++ function: void QFileDevice::unsetError().

C++ documentation:

Sets the file's error to QFileDevice::NoError.

See also error().

Trait Implementations

impl CppDeletable for QSaveFile[src]

unsafe fn delete(&mut self)[src]

Destroys the file object, discarding the saved contents unless commit() was called.

Calls C++ function: virtual [destructor] void QSaveFile::~QSaveFile().

C++ documentation:

Destroys the file object, discarding the saved contents unless commit() was called.

impl Deref for QSaveFile[src]

type Target = QFileDevice

The resulting type after dereferencing.

fn deref(&self) -> &QFileDevice[src]

Calls C++ function: QFileDevice* static_cast<QFileDevice*>(QSaveFile* ptr).

impl DerefMut for QSaveFile[src]

fn deref_mut(&mut self) -> &mut QFileDevice[src]

Calls C++ function: QFileDevice* static_cast<QFileDevice*>(QSaveFile* ptr).

impl DynamicCast<QSaveFile> for QFileDevice[src]

unsafe fn dynamic_cast(ptr: Ptr<QFileDevice>) -> Ptr<QSaveFile>[src]

Calls C++ function: QSaveFile* dynamic_cast<QSaveFile*>(QFileDevice* ptr).

unsafe fn dynamic_cast_mut(ptr: MutPtr<QFileDevice>) -> MutPtr<QSaveFile>[src]

Calls C++ function: QSaveFile* dynamic_cast<QSaveFile*>(QFileDevice* ptr).

impl DynamicCast<QSaveFile> for QIODevice[src]

unsafe fn dynamic_cast(ptr: Ptr<QIODevice>) -> Ptr<QSaveFile>[src]

Calls C++ function: QSaveFile* dynamic_cast<QSaveFile*>(QIODevice* ptr).

unsafe fn dynamic_cast_mut(ptr: MutPtr<QIODevice>) -> MutPtr<QSaveFile>[src]

Calls C++ function: QSaveFile* dynamic_cast<QSaveFile*>(QIODevice* ptr).

impl DynamicCast<QSaveFile> for QObject[src]

unsafe fn dynamic_cast(ptr: Ptr<QObject>) -> Ptr<QSaveFile>[src]

Calls C++ function: QSaveFile* dynamic_cast<QSaveFile*>(QObject* ptr).

unsafe fn dynamic_cast_mut(ptr: MutPtr<QObject>) -> MutPtr<QSaveFile>[src]

Calls C++ function: QSaveFile* dynamic_cast<QSaveFile*>(QObject* ptr).

impl StaticDowncast<QSaveFile> for QFileDevice[src]

unsafe fn static_downcast(ptr: Ptr<QFileDevice>) -> Ptr<QSaveFile>[src]

Calls C++ function: QSaveFile* static_cast<QSaveFile*>(QFileDevice* ptr).

unsafe fn static_downcast_mut(ptr: MutPtr<QFileDevice>) -> MutPtr<QSaveFile>[src]

Calls C++ function: QSaveFile* static_cast<QSaveFile*>(QFileDevice* ptr).

impl StaticDowncast<QSaveFile> for QIODevice[src]

unsafe fn static_downcast(ptr: Ptr<QIODevice>) -> Ptr<QSaveFile>[src]

Calls C++ function: QSaveFile* static_cast<QSaveFile*>(QIODevice* ptr).

unsafe fn static_downcast_mut(ptr: MutPtr<QIODevice>) -> MutPtr<QSaveFile>[src]

Calls C++ function: QSaveFile* static_cast<QSaveFile*>(QIODevice* ptr).

impl StaticDowncast<QSaveFile> for QObject[src]

unsafe fn static_downcast(ptr: Ptr<QObject>) -> Ptr<QSaveFile>[src]

Calls C++ function: QSaveFile* static_cast<QSaveFile*>(QObject* ptr).

unsafe fn static_downcast_mut(ptr: MutPtr<QObject>) -> MutPtr<QSaveFile>[src]

Calls C++ function: QSaveFile* static_cast<QSaveFile*>(QObject* ptr).

impl StaticUpcast<QFileDevice> for QSaveFile[src]

unsafe fn static_upcast(ptr: Ptr<QSaveFile>) -> Ptr<QFileDevice>[src]

Calls C++ function: QFileDevice* static_cast<QFileDevice*>(QSaveFile* ptr).

unsafe fn static_upcast_mut(ptr: MutPtr<QSaveFile>) -> MutPtr<QFileDevice>[src]

Calls C++ function: QFileDevice* static_cast<QFileDevice*>(QSaveFile* ptr).

impl StaticUpcast<QIODevice> for QSaveFile[src]

unsafe fn static_upcast(ptr: Ptr<QSaveFile>) -> Ptr<QIODevice>[src]

Calls C++ function: QIODevice* static_cast<QIODevice*>(QSaveFile* ptr).

unsafe fn static_upcast_mut(ptr: MutPtr<QSaveFile>) -> MutPtr<QIODevice>[src]

Calls C++ function: QIODevice* static_cast<QIODevice*>(QSaveFile* ptr).

impl StaticUpcast<QObject> for QSaveFile[src]

unsafe fn static_upcast(ptr: Ptr<QSaveFile>) -> Ptr<QObject>[src]

Calls C++ function: QObject* static_cast<QObject*>(QSaveFile* ptr).

unsafe fn static_upcast_mut(ptr: MutPtr<QSaveFile>) -> MutPtr<QObject>[src]

Calls C++ function: QObject* static_cast<QObject*>(QSaveFile* ptr).

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T, U> CastInto<U> for T where
    U: CastFrom<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> StaticUpcast<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.