我正在尝试创建一个具有菜单按钮的应用程序。单击按钮后,将出现一个表单。表单是使用插件创建的。问题是 - 第一次单击时,会正常生成一个表单。但是在第二次单击时,会生成另外 2 个表单而不是一个。第 3 次点击提供 3 个更多的表格,依此类推。每次点击我只需要一个表格。
Is this has anything to do with Q_PLUGIN_METADATA(IID "Camel1") in interface?
这是我的应用程序 Mainwindow.cpp
spPlugin *objSpPlugin=new spPlugin;
QSqlQuery qryPlugin=objSpPlugin->view_Plugin_Path(this,publicVariables::inEmployeeId,strFormName,evt::onLoad,true);
while(qryPlugin.next())
{
QString
strPluginPath=qryPlugin.value("Plugin_Path").toString();
qDebug()<<strPluginPath;
QDir pluginsDir(QDir::currentPath()+"/Plugin");
QPluginLoader loader(pluginsDir.absoluteFilePath(strPluginPath));
qDebug()<<loader.fileName();
QObject *obj=loader.instance();
qDebug()<<loader.errorString();
if(obj)
{
MainwindowInterface *objMainWindowInterface=qobject_cast<MainwindowInterface *>(obj);
if(objMainWindowInterface)
{
connect(objMainWindowInterface,SIGNAL(CreateNewFormInstance(QWidget*)),SLOT(createNewFormInstance(QWidget*)));
objMainWindowInterface->run();
}
}
}
void MainWindow::createNewFormInstance(QWidget*frmInstance)
{
qDebug()<<"createNewFormInstance";
if( frmInstance!=NULL)
{
//
}
else
{
ui->mdiArea->addSubWindow(frmInstance);
}
}
My plugin InterFace included in pluginproduct.h
//#ifndef PLUGININTERFACE_H
//#define PLUGININTERFACE_H
//#include<QObject>
//#include<QWidget>
//#include<QtSql/QSqlQuery>
//#include<qsqldatabase.h>
class FormInterface:public QObject
{
Q_OBJECT
public:
virtual void Show()=0;
};
Q_DECLARE_INTERFACE(MainwindowInterface,"Cam1")
//#endif // PLUGININTERFACE_H
My Pluginproduct.h
class LibPluginProductForm:public FormInterface
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "Camel1")
Q_INTERFACES(FormInterface)
public:
LibPluginProductForm();
~ LibPluginProductForm();
void Show();
private:
QWidget *frm;
};
my pluginProduct.cpp
LibPluginProductForm::LibPluginProductForm()
{
frm=new QWidget;
}
LibPluginProductForm::~LibPluginProductForm()
{
}
void LibPluginProductForm::Show()
{
emit CreateNewFormInstance(frm);
qDebug()<<"LibPluginProductForm::Show";
frm->show();`enter code here`
}