Slewman
7th December 2010, 00:11
Im having some problems connecting a signal to a slot in a 2 class, inheritance type structure.
Basically, I have a base class that is waiting for some data to change, once the data gets updated it will send a signal. I have a receiver class (it inherites from the base class) that is supposed to grab the signal and do some processing on the updated data. I have no compile or runtime errors regarding missing slots or unregistered metatypes. Also, I checked the return value of the connect call and it is succeeding. I will post some code to give a better idea of what is going on, but i feel like i have tried everything.
base class header
#include <QObject>
class UIBase : public QObject, public Switch::Subscriber
{
Q_OBJECT
public:
UIBase();
void onData(const std::string&);
signals:
void onNewData();
};
base class cpp file
#include "ui-base.h"
#include <QDebug>
#include <QMetaType>
UIBase::UIBase()
: QObject()
{
}
void UIBase::onData(const std::string &typeID)
{
emit onNewData();
}
Receiver class header
class Receiver : public UIBase
{
Q_OBJECT
public:
Receiver();
public slots:
void onReceiveData();
};
Receiver class cpp
Receiver::Receiver()
{
if (connect(this, SIGNAL(onNewData()), this, SLOT(onReceiveData())))
qDebug() << "SIGNAL/SLOT CONNECTION SUCCESS!";
else
qDebug() << "SIGNAL/SLOT FAILED!";
}
void Receiver::onReceiveData()
{
qDebug() << "SLOT CALLED";
}
Any and all help/suggestions will be greatly appreciated
Basically, I have a base class that is waiting for some data to change, once the data gets updated it will send a signal. I have a receiver class (it inherites from the base class) that is supposed to grab the signal and do some processing on the updated data. I have no compile or runtime errors regarding missing slots or unregistered metatypes. Also, I checked the return value of the connect call and it is succeeding. I will post some code to give a better idea of what is going on, but i feel like i have tried everything.
base class header
#include <QObject>
class UIBase : public QObject, public Switch::Subscriber
{
Q_OBJECT
public:
UIBase();
void onData(const std::string&);
signals:
void onNewData();
};
base class cpp file
#include "ui-base.h"
#include <QDebug>
#include <QMetaType>
UIBase::UIBase()
: QObject()
{
}
void UIBase::onData(const std::string &typeID)
{
emit onNewData();
}
Receiver class header
class Receiver : public UIBase
{
Q_OBJECT
public:
Receiver();
public slots:
void onReceiveData();
};
Receiver class cpp
Receiver::Receiver()
{
if (connect(this, SIGNAL(onNewData()), this, SLOT(onReceiveData())))
qDebug() << "SIGNAL/SLOT CONNECTION SUCCESS!";
else
qDebug() << "SIGNAL/SLOT FAILED!";
}
void Receiver::onReceiveData()
{
qDebug() << "SLOT CALLED";
}
Any and all help/suggestions will be greatly appreciated