Signals emitted from derived class trigger multiple slots
-
Hi,
i have a problem with some signals/slots.I have a base class which contains a signal:
class ModalDialog : public QObject { Q_OBJECT ... signals: void dialogClosed(bool success); };
and two derived classes:
class WaitDeviceDialog : public ModalDialog { Q_OBJECT ... void close() { // Do some crazy stuff... emit dialogClosed(); } };
class ExportDialog : public ModalDialog { Q_OBJECT ... void close() { // Do some other stuff... emit dialogClosed(); } };
In my application i create instances of both derived classes and connect the signals:
... this->exportDlg = new ExportDialog(); this->waitDlg = new WaitDeviceDialog(); ... connect(this->exportDlg, SIGNAL(dialogClosed(bool)), this, SLOT(onExportDialogClosed(bool))); connect(this->waitDlg, SIGNAL(dialogClosed(bool)), this, SLOT(onWaitDialogClosed(bool))); ...
My problem now is, that always both slots are executed regardless of which dialog the signal emitted.
So if the ExportDialog was visible and closed it emitted the dialogClosed event and the corresponding onExportDialogClosed function is called. But also the onWaitDialogClosed function is called and i dont know why...
Does somebody has an idea?
Edit: It's Qt 5.4.1 on a Linux system.
-
@PhTe said in Signals emitted from derived class trigger multiple slots:
emit dialogClosed();
You do not pass true/false to the signal! Your signal has a bool parameter. It should actually not even compile.
-
For some basic steps to debug this I would try:
- comment one connect out. That way youcan actually see if you have the correct connect statement or if somewhere else in the code the problem is happening
- change to the new QT5 Signal/Slot Syntax
@jsulm that is one of the major reasons why I prefere the new over the old Syntax. This would indeed not compile with the new syntax but it should be valid in the old one, but should fail to execute the slot.