from PySide6.QtCore import QPluginLoader
# abc=QPluginLoader.setFileName(os.getcwd()[0])
# print(type(os.path.realpath(os.listdir(os.getcwd())[0])))
# QPluginLoader.fileName(os.path.realpath(os.listdir(os.getcwd())[0]))
abc = QPluginLoader(os.path.realpath(os.listdir(os.getcwd())[0]))
print(type(abc))
plugin = abc.instance() # 返回插件的根组件对象,如有必要将加载插件,如果无法加载或无法实例化,则返回None
errory = abc.errorString() # 返回一个文本字符串 ,包含上次发生的错误说明
# print(abc.staticInstances())
print(abc.metaData()) ##{'IID': 'org.qt-project.Qt.QDesignerCustomWidgetInterface', 'archlevel': 0, 'className': 'gamewidgetPlugin', 'debug': False, 'version': 331264}
print(abc.objectName())
print(abc.fileName())
print(abc)
print(plugin)
print(abc.isLoaded())
这里已经可以将我插件的消息打印出来,但是不知道该如何穿换成我需要的小部件、而我在c++中是这样做的
QObject *plugin = loader.instance();
if (plugin)
{
QDesignerCustomWidgetInterface *iCustomWidgetInterface = qobject_cast<QDesignerCustomWidgetInterface *>(plugin);
if( iCustomWidgetInterface ){
QWidget *widget = iCustomWidgetInterface->createWidget( parent );
return widget;
}
}
else
qDebug("loader.instance() error\r\n");
return NULL;