[Solved] Problem when disconnecting Signals!
-
i have a mainwindow with a button..
when you press the button it opens a dialog:@void MainWindow::on_pushButton_clicked()
{
Dialogosre = new Dialogos(this);
connect(this,SIGNAL(check_name_on_add()),Dialogosre,SLOT(final_check()));
connect(Dialogosre,SIGNAL(run_ante()),this,SLOT(ante()));
Dialogosre->show();
}@also the mainwindows has another void ( which i want to be executed from the dialog )
@void MainWindow::ante()
{
Q_EMIT check_name_on_add();
disconnect(this, 0, Dialogosre, 0);
}@the dialog has a button
when i press the button
i want the void::ante to be executed:@void Dialogos::on_pushButton_clicked()
{
Q_EMIT run_ante();
}@which will execute another void that the dialog has:
@void Dialogos::final_check()
{
QMessageBox::critical(this, " ","<h3>Blablabla</h3>\nBlablabla","Close");
}@So the problem is that when i press the button at the dialog the messagebox is beeing shown. But if close the messagebox and repress the button the messagebox will not be shown cause of the disconnect. I must have disconnect cause without it, if i open the dialog, close the dialog and reopen the dialog and then press the button the messagebox will be shown 2 times. Any ideas? For simplicity reasons here is an example to reproduse it: http://www.megaupload.com/?d=EW1BK3SX
Thanks for any answers!
-
[quote author="Leon" date="1315573779"]
@void MainWindow::on_pushButton_clicked()
{
Dialogosre = new Dialogos(this);
connect(this,SIGNAL(check_name_on_add()),Dialogosre,SLOT(final_check()));
connect(Dialogosre,SIGNAL(run_ante()),this,SLOT(ante()));
Dialogosre->show();
}@
@void MainWindow::ante()
{
Q_EMIT check_name_on_add();
disconnect(this, 0, Dialogosre, 0);
}@
[/quote]I guess your problem is in the first routine. You create the object with new, but you are not deleting it. Next time you are in the first method, you are creating a new object. Furthermore, you have a memory leak.
If you initialze in the creator of MainWindow to zero, you can do:
@void MainWindow::on_pushButton_clicked()
{
delete Dialogosre;
Dialogosre = new Dialogos(this);
connect(this,SIGNAL(check_name_on_add()),Dialogosre,SLOT(final_check()));
connect(Dialogosre,SIGNAL(run_ante()),this,SLOT(ante()));
Dialogosre->show();
}@Again this needs a initialization of Dialogosre. For instance like:
@
MainWindow::MainWindow()
: Dialogosre ( 0 )
{}
@
or something similar somewhere in your code.
Deleting the object is disconnecting it as well.