[SOLVED] New signal/slot doesn't work in the same class with different instances
-
Hi!
I tried to connect a signal and a slot of the same class to different instances using the new connect-syntax. Result: doesn't work. The signal is emitted but the slot is never called. If i use the old syntax with SIGNAL() and SLOT() is works with no problems. Any idea why?
Here's the class header:
@
#ifndef PLUGINWIDGET_H
#define PLUGINWIDGET_H#include <QWidget>
#include "../generallibrary_global.h"class LogTextEdit;
class LogWidget;/*!
\brief*/
class PluginWidget : public QWidget
{
Q_OBJECT
public:/*! \brief \param parent */ explicit PluginWidget(QWidget * parent); /*! \brief \return LogTextEdit */ LogTextEdit * getLogTextEdit() const; /*! \brief \param getLogTextEdit */ void setLogTextEdit(LogTextEdit *getLogTextEdit); /*! \brief */ void show(); /*! \brief \return LogWidget */ LogWidget *getLogWidget() const; /*! \brief \param getLogWidget */ void setLogWidget(LogWidget *getLogWidget); /*! \brief \return QWidget */ QWidget *ContainerWidget() const; /*! \brief \param ContainerWidget */ void setContainerWidget(QWidget *ContainerWidget); /*! \brief */ virtual void initAfterShow() = 0; /*! \brief */ virtual void initBeforeShow() = 0; QString PluginDirectory() const; void setPluginDirectory(const QString &PluginDirectory); void registerToGetData(QString datatype);
signals:
void dataSignal(QString datatype, void * data);
public slots:
void dataSlot(QString datatype, void * data);
private:
LogTextEdit * m_logTextEdit; /*!< TODO /
LogWidget * m_logWidget;
int m_PluginIndex;
QWidget * m_ContainerWidget; /!< The container in which this widget is nested */
QString m_sPluginDirectory;
bool m_wasShownBefore;
QStringList m_sDataTypes;
};#endif // PLUGINWIDGET_H
@
And now the way i connect it:
@
connect(pluginoutputdata->getPluginMainWidget(), &PluginWidget::dataSignal, plugininputdata->getPluginMainWidget(), &PluginWidget::dataSlot);
@It simply does not work. Thank you for your help and have a nice day :-)
-
What errros are you getting?
-
Hi!
Ups...i've forgotten the error:
@QObject::connect: signal not found in@
Thank you!
-
And i'm using a derived class...
-
Would it help if you add the function mask?
@connect(pluginoutputdata->getPluginMainWidget(), &PluginWidget::dataSignal(QString, void *) , plugininputdata->getPluginMainWidget(), &PluginWidget::dataSlot(QString, void *));@
-
Hi!
No, doesn't help. There must be a trick. I'm sure i'm not the first person with this problem. Maybe i used the wrong search terms to find a post here...
-
Hmm, maybe something with the vtables, in your class declaration:
@QWidget * m_ContainerWidget; /*!< The container in which this widget is nested */@so if pluginoutputdata->getPluginMainWidget() inside your connect() returns a QWidget instead of a PluginWidget then dataSignal/dataSlot would be unknown methods.
-
Are you sure that using the regular SIGNAL/SLOT macros the connection works? Did you check the return value?
-
Yes. The old way works. But i found it. It's solved.
The problem was that i subclassed it and did not use the right way. The slot in the base class was not virtual. Thats it.
Thank you for your help!