PySide.QtCore.QResource class provides an interface for reading directly from resources.
PySide.QtCore.QResource is an object that represents a set of data (and possibly children) relating to a single resource entity. PySide.QtCore.QResource gives 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 with PySide.QtCore.QFile . The data and children behind a PySide.QtCore.QResource are 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 PySide.QtCore.QResource can 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 by QDir.searchPaths() .
A PySide.QtCore.QResource that is representing a file will have data backing it, this data can possibly be compressed, in which case qUncompress() must be used to access the real data; this happens implicitly when accessed through a PySide.QtCore.QFile . A PySide.QtCore.QResource that 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 PySide.QtCore.QResource.registerResource() function. The resource file passed into PySide.QtCore.QResource.registerResource() 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 PySide.QtCore.QResource.setFileName() .
PySide.QtCore.QResource.unregisterResource() function removes a reference to a particular file. If there are QResources 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 further PySide.QtCore.QResource can be created pointing into this resource data. The resource itself will be unmapped from memory when the last PySide.QtCore.QResource that points to it is destroyed.
另请参阅
Qt 资源系统 PySide.QtCore.QFile PySide.QtCore.QDir PySide.QtCore.QFileInfo
| 参数: |
|
|---|
构造 PySide.QtCore.QResource pointing to file . locale is used to load a specific localization of a resource data.
| 返回类型: | unicode |
|---|
Returns the real path that this PySide.QtCore.QResource represents, if the resource was found via the QDir.searchPaths() it will be indicated in the path.
| 参数: | path – unicode |
|---|
使用 QDir.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 PySide.QtCore.QResource creation.
| 返回类型: | 字符串列表 |
|---|
Returns a list of all resources in this directory, if the resource represents a file the list will be empty.
| 返回类型: | 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.
| 返回类型: | unicode |
|---|
Returns the full path to the file that this PySide.QtCore.QResource represents as it was passed.
| 返回类型: | PySide.QtCore.bool |
|---|
Returns true if the resource represents a file and the data backing it is in a compressed format, false otherwise.
| 返回类型: | PySide.QtCore.bool |
|---|
Returns true if the resource represents a directory and thus may have PySide.QtCore.QResource.children() in it, false if it represents a file.
| 返回类型: | PySide.QtCore.bool |
|---|
Returns true if the resource represents a file and thus has data backing it, false if it represents a directory.
| 返回类型: | PySide.QtCore.bool |
|---|
Returns true if the resource really exists in the resource hierarchy, false otherwise.
| 返回类型: | PySide.QtCore.QLocale |
|---|
Returns the locale used to locate the data for the PySide.QtCore.QResource .
| 参数: |
|
|---|---|
| 返回类型: |
PySide.QtCore.bool |
Registers the resource with the given rccFileName at the location in the resource tree specified by mapRoot , and returns true if the file is successfully opened; otherwise returns false.
| 参数: |
|
|---|---|
| 返回类型: |
PySide.QtCore.bool |
Registers the resource with the given rccData at the location in the resource tree specified by mapRoot , and returns true if the file is successfully opened; otherwise returns false.
警告
The data must remain valid throughout the life of any PySide.QtCore.QFile that may reference the resource data.
| 返回类型: | 字符串列表 |
|---|
使用 QDir.searchPaths() 代替。
Returns the current search path list. This list is consulted when creating a relative resource.
| 参数: | file – unicode |
|---|
设置 PySide.QtCore.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 QDir.searchPaths() .
| 参数: | locale – PySide.QtCore.QLocale |
|---|
设置 PySide.QtCore.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.
| 返回类型: | PySide.QtCore.qint64 |
|---|
Returns the size of the data backing the resource.
| 参数: |
|
|---|---|
| 返回类型: |
PySide.QtCore.bool |
Unregisters the resource with the given rccFileName at the location in the resource tree specified by mapRoot , and returns true if the resource is successfully unloaded and no references exist for the resource; otherwise returns false.
| 参数: |
|
|---|---|
| 返回类型: |
PySide.QtCore.bool |
Unregisters the resource with the given rccData at the location in the resource tree specified by mapRoot , and returns true if the resource is successfully unloaded and no references exist into the resource; otherwise returns false.