PySide6.QtCore.QFileDevice¶
- class QFileDevice¶
- The - QFileDeviceclass provides an interface for reading from and writing to open files. More…- Inherited by: - QSaveFile,- QFile,- QTemporaryFile- Synopsis¶- Methods¶- def - __init__()
- def - error()
- def - fileTime()
- def - flush()
- def - handle()
- def - map()
- def - setFileTime()
- def - unmap()
- def - unsetError()
 - Virtual methods¶- def - fileName()
- def - permissions()
- def - resize()
- def - setPermissions()
 - Note - This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE - Detailed Description¶- QFileDeviceis the base class for I/O devices that can read and write text and binary files and resources .- QFileoffers the main functionality,- QFileDeviceserves as a base class for sharing functionality with other file devices such as- QSaveFile, by providing all the operations that can be done on files that have been opened by- QFileor- QSaveFile.- class FileError¶
- This enum describes the errors that may be returned by the - error()function.- Constant - Description - QFileDevice.NoError - No error occurred. - QFileDevice.ReadError - An error occurred when reading from the file. - QFileDevice.WriteError - An error occurred when writing to the file. - QFileDevice.FatalError - A fatal error occurred. - QFileDevice.ResourceError - Out of resources (e.g., too many open files, out of memory, etc.) - QFileDevice.OpenError - The file could not be opened. - QFileDevice.AbortError - The operation was aborted. - QFileDevice.TimeOutError - A timeout occurred. - QFileDevice.UnspecifiedError - An unspecified error occurred. - QFileDevice.RemoveError - The file could not be removed. - QFileDevice.RenameError - The file could not be renamed. - QFileDevice.PositionError - The position in the file could not be changed. - QFileDevice.ResizeError - The file could not be resized. - QFileDevice.PermissionsError - The file could not be accessed. - QFileDevice.CopyError - The file could not be copied. 
 - class FileTime¶
- This enum is used by the - fileTime()and- setFileTime()functions.- Constant - Description - QFileDevice.FileAccessTime - When the file was most recently accessed (e.g. read or written to). - QFileDevice.FileBirthTime - When the file was created (may not be not supported on UNIX). - QFileDevice.FileMetadataChangeTime - When the file’s metadata was last changed. - QFileDevice.FileModificationTime - When the file was most recently modified. - See also 
 - class Permission¶
- Warning - This section contains snippets that were automatically translated from C++ to Python and may contain errors. - (inherits - enum.Flag) 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 - Description - QFileDevice.ReadOwner - The file is readable by the owner of the file. - QFileDevice.WriteOwner - The file is writable by the owner of the file. - QFileDevice.ExeOwner - The file is executable by the owner of the file. - QFileDevice.ReadUser - The file is readable by the user. - QFileDevice.WriteUser - The file is writable by the user. - QFileDevice.ExeUser - The file is executable by the user. - QFileDevice.ReadGroup - The file is readable by the group. - QFileDevice.WriteGroup - The file is writable by the group. - QFileDevice.ExeGroup - The file is executable by the group. - QFileDevice.ReadOther - The file is readable by others. - QFileDevice.WriteOther - The file is writable by others. - QFileDevice.ExeOther - The file is executable by others. - Warning - Because of differences in the platforms supported by Qt, 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. This behavior might change in a future Qt version. - Note - On NTFS file systems, ownership and permissions checking is disabled by default for performance reasons. To enable it, include the following line: - Q_CORE_EXPORT = extern() - Permission checking is then turned on and off by incrementing and decrementing - qt_ntfs_permission_lookupby 1.- qt_ntfs_permission_lookup++ # turn checking on qt_ntfs_permission_lookup-- # turn it off again - Note - Since this is a non-atomic global variable, it is only safe to increment or decrement - qt_ntfs_permission_lookupbefore any threads other than the main thread have started or after every thread other than the main thread has ended.- Note - From Qt 6.6 the variable - qt_ntfs_permission_lookupis deprecated. Please use the following alternatives.- The safe and easy way to manage permission checks is to use the RAII class - QNtfsPermissionCheckGuard.- def complexFunction(): QNtfsPermissionCheckGuard permissionGuard # check is enabled # do complex things here that need permission check enabled } // as the guard goes out of scope the check is disabled - If you need more fine-grained control, it is possible to manage the permission with the following functions instead: - qAreNtfsPermissionChecksEnabled() # check status qEnableNtfsPermissionChecks() # turn checking on qDisableNtfsPermissionChecks() # turn it off again 
 - class FileHandleFlag¶
- (inherits - enum.Flag) This enum is used when opening a file to specify additional options which only apply to files and not to a generic- QIODevice.- Constant - Description - QFileDevice.AutoCloseHandle - 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 Qt always owns the file handle and must close it.- QFileDevice.DontCloseHandle - If not explicitly closed, the underlying file handle is left open when the - QFileobject is destroyed.
 - class MemoryMapFlag¶
- (inherits - enum.Flag) This enum describes special options that may be used by the- map()function.- Constant - Description - QFileDevice.NoOptions - No options. - QFileDevice.MapPrivateOption - The mapped memory will be private, so any modifications will not be visible to other processes and will not be written to disk. Any such modifications will be lost when the memory is unmapped. It is unspecified whether modifications made to the file made after the mapping is created will be visible through the mapped memory. This enum value was introduced in Qt 5.4. 
 - __init__()¶
 - __init__(parent)
- Parameters:
- parent – - QObject
 
 - 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 - fileName()¶
- Return type:
- str 
 
 - Returns the name of the file. The default implementation in - QFileDevicereturns a null string.- Returns the file time specified by - time. If the time cannot be determined return QDateTime() (an invalid date time).- See also - flush()¶
- Return type:
- bool 
 
 - Flushes any buffered data to the file. Returns - trueif successful; otherwise returns- false.- handle()¶
- Return type:
- int 
 
 - 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- QSocketNotifieras well.- If the file is not open, or there is an error, handle() returns -1. - See also - map(offset, size[, flags=QFileDevice.MemoryMapFlag.NoOptions])¶
- Parameters:
- offset – int 
- size – int 
- flags – Combination of - MemoryMapFlag
 
- Return type:
- PyObject 
 
 - Maps - sizebytes 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- QFileis 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 - Noneif there is an error.- See also - permissions()¶
- Return type:
- Combination of - Permission
 
 - Returns the complete OR-ed together combination of QFile::Permission for the file. - See also - resize(sz)¶
- Parameters:
- sz – int 
- Return type:
- bool 
 
 - Sets the file size (in bytes) - sz. Returns- trueif the resize succeeds; false otherwise. If- szis larger than the file currently is, the new bytes will be set to 0; if- szis smaller, the file is simply truncated.- Warning - This function can fail if the file doesn’t exist. - See also - size()- setFileTime(newDate, fileTime)¶
 - Sets the file time specified by - fileTimeto- newDate, returning true if successful; otherwise returns false.- setPermissions(permissionSpec)¶
- Parameters:
- permissionSpec – Combination of - Permission
- Return type:
- bool 
 
 - Sets the permissions for the file to the - permissionsspecified. Returns- trueif successful, or- falseif the permissions cannot be modified.- Warning - This function does not manipulate ACLs, which may limit its effectiveness. - See also - unmap(address)¶
- Parameters:
- address – str 
- Return type:
- bool 
 
 - Unmaps the memory - address.- Returns - trueif the unmap succeeds; false otherwise.- See also - unsetError()¶
 - Sets the file’s error to - NoError.- See also