QPluginLoaderclass loads a plugin at run-time. 更多 …
def
errorString
()
def
fileName
()
def
instance
()
def
isLoaded
()
def
load
()
def
metaData
()
def
setFileName
(fileName)
def
unload
()
def
staticInstances
()
QPluginLoaderprovides access to a Qt plugin. A Qt plugin is stored in a shared library (a DLL) and offers these benefits over shared libraries accessed usingQLibrary:
QPluginLoaderchecks that a plugin is linked against the same version of Qt as the application.
QPluginLoaderprovides direct access to a root component object (instance()), instead of forcing you to resolve a C function manually.An instance of a
QPluginLoaderobject operates on a single shared library file, which we call a plugin. It provides access to the functionality in the plugin in a platform-independent way. To specify which plugin to load, either pass a file name in the constructor or set it withsetFileName().最重要功能是
load()to dynamically load the plugin file,isLoaded()to check whether loading was successful, andinstance()to access the root component in the plugin. Theinstance()function implicitly tries to load the plugin if it has not been loaded yet. Multiple instances ofQPluginLoadercan be used to access the same physical plugin.Once loaded, plugins remain in memory until all instances of
QPluginLoaderhas been unloaded, or until the application terminates. You can attempt to unload a plugin usingunload(), but if other instances ofQPluginLoaderare using the same library, the call will fail, and unloading will only happen when every instance has calledunload(). Right before the unloading happens, the root component will also be deleted.See How to Create Qt Plugins for more information about how to make your application extensible through plugins.
注意:
QPluginLoadercannot be used if your application is statically linked against Qt. In this case, you will also have to link to plugins statically. You can useQLibraryif you need to load dynamic libraries in a statically linked application.另请参阅
QLibrary插件 & 描绘范例
QPluginLoader
(
[
parent=None
]
)
¶
QPluginLoader(fileName[, parent=None])
- param parent
- param fileName
unicode
构造插件加载器采用给定
parent
.
构造插件加载器采用给定
parent
将加载指定插件通过
fileName
.
To be loadable, the file’s suffix must be a valid suffix for a loadable library in accordance with the platform, e.g.
.so
在 Unix,
.dylib
在 macOS 和 iOS,及
.dll
在 Windows。可以验证后缀采用
isLibrary()
.
另请参阅
PySide2.QtCore.QPluginLoader.
errorString
(
)
¶
unicode
Returns a text string with the description of the last error that occurred.
PySide2.QtCore.QPluginLoader.
fileName
(
)
¶
unicode
另请参阅
PySide2.QtCore.QPluginLoader.
instance
(
)
¶
返回插件的根组件对象。插件被加载若有必要。函数返回
None
若插件无法被加载或根组件对象无法被实例化。
若根组件对象被销毁,调用此函创建新实例。
不会删除由此函数返回的根组件当
QPluginLoader
被销毁时。若想要确保删除根组件,应该调用
unload()
as soon you don’t need to access the core component anymore. When the library is finally unloaded, the root component will automatically be deleted.
组件对象是
QObject
。使用
qobject_cast()
to access interfaces you are interested in.
另请参阅
PySide2.QtCore.QPluginLoader.
load
(
)
¶
bool
加载插件并返回
true
若插件加载成功;否则返回
false
。由于
instance()
always calls this function before resolving any symbols it is not necessary to call it explicitly. In some situations you might want the plugin loaded in advance, in which case you would use this function.
另请参阅
PySide2.QtCore.QPluginLoader.
metaData
(
)
¶
QJsonObject
Returns the meta data for this plugin. The meta data is data specified in a json format using the
Q_PLUGIN_METADATA()
macro when compiling the plugin.
The meta data can be queried in a fast and inexpensive way without actually loading the plugin. This makes it possible to e.g. store capabilities of the plugin in there, and make the decision whether to load the plugin dependent on this meta data.
PySide2.QtCore.QPluginLoader.
setFileName
(
fileName
)
¶
fileName – unicode
另请参阅
PySide2.QtCore.QPluginLoader.
staticInstances
(
)
¶
Returns a list of static plugin instances (root components) held by the plugin loader.
另请参阅
staticPlugins()
PySide2.QtCore.QPluginLoader.
unload
(
)
¶
bool
卸载插件并返回
true
若插件可以被卸载;否则返回
false
.
This happens automatically on application termination, so you shouldn’t normally need to call this function.
If other instances of
QPluginLoader
are using the same plugin, the call will fail, and unloading will only happen when every instance has called .
Don’t try to delete the root component. Instead rely on that will automatically delete it when needed.
另请参阅