Reputation: 41
I am trying to Create an Application having a Menu Button. on Clicking the button, a form will be appeared. The Form is created using plugin. The issue is- on first click, one form is generated as normal. But on second click 2 more forms generated instead of one. 3rd click gives 3 more forms and so on. I need only one form with each click.
Is this has anything to do with Q_PLUGIN_METADATA(IID "Camel1") in interface?
This is My Application 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`
}
Upvotes: 3
Views: 768
Reputation: 5760
The signal will be raised when the 'CreaeNewFormInstance' is called but also from LibPluginProduceForm::Show where you are manually 'emitting' the signal.
Check that your 'Show' method is not being called multiple times. Are you seeing your debug statement in the Application Output ?
Upvotes: 1