QFileDeviceclass provides an interface for reading from and writing to open files. 更多 …
继承者: QFile , QSaveFile , QTemporaryFile
New in version 5.0.
def
error
()
def
fileTime
(time)
def
flush
()
def
handle
()
def
map
(offset, size[, flags=NoOptions])
def
setFileTime
(newDate, fileTime)
def
unmap
(address)
def
unsetError
()
def
fileName
()
def
permissions
()
def
resize
(sz)
def
setPermissions
(permissionSpec)
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 asQTemporaryFile, by providing all the operations that can be done on files that have been opened byQFileorQTemporaryFile.另请参阅
PySide2.QtCore.QFileDevice.
FileError
¶
此枚举描述可能的错误,错误返回通过
error()
函数。
|
常量 |
描述 |
|---|---|
|
QFileDevice.NoError |
没有发生错误。 |
|
QFileDevice.ReadError |
An error occurred when reading from the file. |
|
QFileDevice.WriteError |
An error occurred when writing to the file. |
|
QFileDevice.FatalError |
发生致命错误。 |
|
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 |
发生超时。 |
|
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. |
PySide2.QtCore.QFileDevice.
FileTime
¶
This enum is used by the
fileTime()
and
setFileTime()
函数。
|
常量 |
描述 |
|---|---|
|
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. |
另请参阅
setFileTime()
fileTime()
fileTime()
New in version 5.10.
PySide2.QtCore.QFileDevice.
Permission
¶
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.
|
常量 |
描述 |
|---|---|
|
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 |
文件对于用户是可读的。 |
|
QFileDevice.WriteUser |
文件对于用户是可写的。 |
|
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 anyone. |
|
QFileDevice.WriteOther |
The file is writable by anyone. |
|
QFileDevice.ExeOther |
The file is executable by anyone. |
警告
Because of differences in the platforms supported by Qt, the semantics of , and 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.
注意
On NTFS file systems, ownership and permissions checking is disabled by default for performance reasons. To enable it, include the following line:
extern Q_CORE_EXPORT int qt_ntfs_permission_lookup;
Permission checking is then turned on and off by incrementing and decrementing
qt_ntfs_permission_lookup
by 1.
qt_ntfs_permission_lookup += 1 // turn checking on
qt_ntfs_permission_lookup += 1 // turn it off again
PySide2.QtCore.QFileDevice.
FileHandleFlag
¶
This enum is used when opening a file to specify additional options which only apply to files and not to a generic
QIODevice
.
|
常量 |
描述 |
|---|---|
|
QFileDevice.AutoCloseHandle |
The file handle passed into
|
|
QFileDevice.DontCloseHandle |
If not explicitly closed, the underlying file handle is left open when the
|
PySide2.QtCore.QFileDevice.
MemoryMapFlags
¶
This enum describes special options that may be used by the
map()
函数。
|
常量 |
描述 |
|---|---|
|
QFileDevice.NoOptions |
没有选项。 |
|
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. |
PySide2.QtCore.QFileDevice.
error
(
)
¶
Returns the file error status.
I/O 设备状态返回错误代码。例如,若
open()
返回
false
, or a read/write operation returns -1, this function can be called to find out the reason why the operation failed.
另请参阅
PySide2.QtCore.QFileDevice.
fileName
(
)
¶
unicode
Returns the name of the file. The default implementation in
QFileDevice
returns a null string.
PySide2.QtCore.QFileDevice.
fileTime
(
time
)
¶
Returns the file time specified by
time
. If the time cannot be determined return QDateTime() (an invalid date time).
另请参阅
setFileTime()
FileTime
isValid()
PySide2.QtCore.QFileDevice.
flush
(
)
¶
bool
Flushes any buffered data to the file. Returns
true
若成功;否则返回
false
.
PySide2.QtCore.QFileDevice.
handle
(
)
¶
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
QSocketNotifier
as well.
If the file is not open, or there is an error, returns -1.
另请参阅
PySide2.QtCore.QFileDevice.
map
(
offset
,
size
[
,
flags=NoOptions
]
)
¶
offset
–
qint64
size
–
qint64
flags
–
MemoryMapFlags
PyObject
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
None
if there is an error.
另请参阅
PySide2.QtCore.QFileDevice.
permissions
(
)
¶
Permissions
Returns the complete OR-ed together combination of
Permission
for the file.
另请参阅
PySide2.QtCore.QFileDevice.
resize
(
sz
)
¶
sz
–
qint64
bool
Sets the file size (in bytes)
sz
。返回
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.
警告
This function can fail if the file doesn’t exist.
另请参阅
size()
PySide2.QtCore.QFileDevice.
setFileTime
(
newDate
,
fileTime
)
¶
Sets the file time specified by
fileTime
to
newDate
, returning true if successful; otherwise returns false.
注意
The file must be open to use this function.
另请参阅
fileTime()
FileTime
PySide2.QtCore.QFileDevice.
setPermissions
(
permissionSpec
)
¶
permissionSpec
–
Permissions
bool
Sets the permissions for the file to the
permissions
指定。返回
true
若成功,或
false
若权限不能被修改。
警告
此函数不操纵 ACL (访问控制列表),这可能限制其有效性。
另请参阅
PySide2.QtCore.QFileDevice.
unmap
(
address
)
¶
address
–
uchar
bool
取消映射内存
address
.
返回
true
若取消映射成功;否则 false。
另请参阅