def
absoluteFilePath
()
def
children
()
def
compressionAlgorithm
()
def
data
()
def
fileName
()
def
isCompressed
()
def
isDir
()
def
isFile
()
def
isValid
()
def
lastModified
()
def
locale
()
def
setFileName
(file)
def
setLocale
(locale)
def
size
()
def
uncompressedData
()
def
uncompressedSize
()
def
addSearchPath
(path)
def
registerResource
(rccFilename[, resourceRoot=””])
def
registerResourceData
(rccData[, resourceRoot=””])
def
searchPaths
()
def
unregisterResource
(rccFilename[, resourceRoot=””])
def
unregisterResourceData
(rccData[, resourceRoot=””])
QResourceis an object that represents a set of data (and possibly children) relating to a single resource entity.QResourcegives direct access to the bytes in their raw format. In this way direct access allows reading data without buffer copying or indirection. Indirection is often useful when interacting with the resource entity as if it is a file, this can be achieved withQFile. The data and children behind aQResourceare normally compiled into an application/library, but it is also possible to load a resource at runtime. When loaded at run time the resource file will be loaded as one big set of data and then given out in pieces via references into the resource tree.A
QResourcecan either be loaded with an absolute path, either treated as a file system rooted with a/character, or in resource notation rooted with a:character. A relative resource can also be opened which will be found in the list of paths returned bysearchPaths().A
QResourcethat is representing a file will have data backing it, this data can possibly be compressed, in which caseqUncompress()must be used to access the real data; this happens implicitly when accessed through aQFile. AQResourcethat is representing a directory will have only children and no data.
A resource can be left out of an application’s binary and loaded when it is needed at run-time by using the
registerResource()function. The resource file passed intoregisterResource()must be a binary resource as created by rcc. Further information about binary resources can be found in Qt 资源系统 文档编制。This can often be useful when loading a large set of application icons that may change based on a setting, or that can be edited by a user and later recreated. The resource is immediately loaded into memory, either as a result of a single file read operation, or as a memory mapped file.
This approach can prove to be a significant performance gain as only a single file will be loaded, and pieces of data will be given out via the path requested in
setFileName().
unregisterResource()function removes a reference to a particular file. If there areQResourceobjects that currently reference resources related to the unregistered file, they will continue to be valid but the resource file itself will be removed from the resource roots, and thus no furtherQResourcecan be created pointing into this resource data. The resource itself will be unmapped from memory when the lastQResourcethat points to it is destroyed.
QResource
(
[
file=""
[
,
locale=QLocale()
]
]
)
¶
- param locale
- param file
unicode
构造
QResource
pointing to
file
.
locale
is used to load a specific localization of a resource data.
PySide2.QtCore.QResource.
压缩
¶
此枚举用于
compressionAlgorithm()
to indicate which algorithm the RCC tool used to compress the payload.
|
常量 |
描述 |
|---|---|
|
QResource.NoCompression |
内容未压缩 |
|
QResource.ZlibCompression |
内容被压缩使用
zlib
and can be decompressed using the
|
|
QResource.ZstdCompression |
内容被压缩使用
zstd
. To decompress, use the
|
New in version 5.13.
PySide2.QtCore.QResource.
absoluteFilePath
(
)
¶
unicode
Returns the real path that this
QResource
represents, if the resource was found via the
searchPaths()
it will be indicated in the path.
另请参阅
PySide2.QtCore.QResource.
addSearchPath
(
path
)
¶
path – unicode
注意
此函数被弃用。
使用
addSearchPath()
with a prefix instead.
添加
path
to the search paths searched in to find resources that are not specified with an absolute path. The
path
must be an absolute path (start with
/
).
The default search path is to search only in the root (
:/
). The last path added will be consulted first upon next
QResource
creation.
PySide2.QtCore.QResource.
children
(
)
¶
字符串列表
Returns a list of all resources in this directory, if the resource represents a file the list will be empty.
另请参阅
PySide2.QtCore.QResource.
compressionAlgorithm
(
)
¶
Returns the compression type that this resource is compressed with, if any. If it is not compressed, this function returns
NoCompression
.
若此函数返回
ZlibCompression
, you may decompress the data using the
qUncompress()
function. Up until Qt 5.13, this was the only possible compression algorithm.
若此函数返回
ZstdCompression
, you need to use the Zstandard library functios (
<zstd.h>
header).
Qt
does
not
provide
a
wrapper.
见
\l{http://facebook.github.io/zstd/zstd_manual.html}{Zstandard
manual}.
\sa
data(),
isFile()
PySide2.QtCore.QResource.
data
(
)
¶
PyObject
Returns a read only buffer object pointing to the segment of data that this resource represents. If the resource is compressed the data returns is compressed and qUncompress() must be used to access the data. If the resource is a directory None is returned.
PySide2.QtCore.QResource.
fileName
(
)
¶
unicode
Returns the full path to the file that this
QResource
represents as it was passed.
PySide2.QtCore.QResource.
isCompressed
(
)
¶
bool
注意
此函数被弃用。
返回
true
if the resource represents a file and the data backing it is in a compressed format, false otherwise. If the data is compressed, check
compressionAlgorithm()
to verify what algorithm to use to decompress the data.
注意
This function is deprecated and can be replaced with
compressionAlgorithm() != NoCompression
PySide2.QtCore.QResource.
isDir
(
)
¶
bool
返回
true
if the resource represents a directory and thus may have
children()
in it, false if it represents a file.
另请参阅
PySide2.QtCore.QResource.
isFile
(
)
¶
bool
返回
true
if the resource represents a file and thus has data backing it, false if it represents a directory.
另请参阅
PySide2.QtCore.QResource.
isValid
(
)
¶
bool
返回
true
if the resource really exists in the resource hierarchy, false otherwise.
PySide2.QtCore.QResource.
lastModified
(
)
¶
Returns the date and time when the file was last modified before packaging into a resource.
PySide2.QtCore.QResource.
locale
(
)
¶
Returns the locale used to locate the data for the
QResource
.
另请参阅
PySide2.QtCore.QResource.
registerResource
(
rccFilename
[
,
resourceRoot=""
]
)
¶
rccFilename – unicode
resourceRoot – unicode
bool
PySide2.QtCore.QResource.
registerResourceData
(
rccData
[
,
resourceRoot=""
]
)
¶
rccData
–
uchar
resourceRoot – unicode
bool
PySide2.QtCore.QResource.
searchPaths
(
)
¶
字符串列表
注意
此函数被弃用。
使用
searchPaths()
代替。
Returns the current search path list. This list is consulted when creating a relative resource.
PySide2.QtCore.QResource.
setFileName
(
file
)
¶
file – unicode
设置
QResource
to point to
file
.
file
can either be absolute, in which case it is opened directly, if relative then the file will be tried to be found in
searchPaths()
.
PySide2.QtCore.QResource.
setLocale
(
locale
)
¶
locale
–
QLocale
设置
QResource
to only load the localization of resource to for
locale
. If a resource for the specific locale is not found then the C locale is used.
另请参阅
PySide2.QtCore.QResource.
size
(
)
¶
qint64
Returns the size of the stored data backing the resource.
If the resource is compressed, this function returns the size of the compressed data. See
uncompressedSize()
for the uncompressed size.
PySide2.QtCore.QResource.
uncompressedData
(
)
¶
Returns the resource data, decompressing it first, if the data was stored compressed. If the resource is a directory or an error occurs while decompressing, a null
QByteArray
被返回。
注意
If the data was compressed, this function will decompress every time it is called. The result is not cached between calls.
PySide2.QtCore.QResource.
uncompressedSize
(
)
¶
qint64
Returns the size of the data in this resource. If the data was not compressed, this function returns the same as
size()
. If it was, then this function extracts the size of the original uncompressed data from the stored stream.
PySide2.QtCore.QResource.
unregisterResource
(
rccFilename
[
,
resourceRoot=""
]
)
¶
rccFilename – unicode
resourceRoot – unicode
bool
PySide2.QtCore.QResource.
unregisterResourceData
(
rccData
[
,
resourceRoot=""
]
)
¶
rccData
–
uchar
resourceRoot – unicode
bool