Reputation: 11651
While trying to familiarize myself to the signal slot concept. I came up with the following code
class Person: public QObject
{
Q_OBJECT
public:
void SignalEmitter(QString Words); //This emits the signal
Person(QObject *parent = 0);
signals:
void Call(QString Words); //This is the signal
};
class Animal: public QObject
{
Q_OBJECT
public:
Animal(QObject *parent = 0);
public slots:
void Respond(QString Words); //This is the slot
};
class SomeClass: public QObject
{
Q_OBJECT
public:
SomeClass(QObject *parent = 0);
};
Now the objective is simple - The person sends a signal and the animal receives it in a slot Here is my implementation
void Person::SignalEmitter(QString Words)
{
//Emit the signal
emit Call("Signal emitted");
}
void Animal::Respond(QString Words)
{
qDebug() <<"Responding " << Words;
std::string d= "Breakpoint should be here";
}
//This is the code
SomeClass::SomeClass(QObject *parent):QObject(parent)
{
Person *p = new Person();
Animal *a = new Animal();
connect(p,SIGNAL(SignalEmitter(QString)) ,a,SLOT(Respond(QString)));
p->SignalEmitter("Lassie");
std::string d = "dd";
}
Unfortunately the breakpoint never hits Animal::Respond(QString Words)
any suggestions on what I might be doing wrong ?
Upvotes: 1
Views: 144
Reputation: 1123
I believe the SIGNAL in the following
connect(p,SIGNAL(SignalEmitter(QString)) ,a,SLOT(Respond(QString)));
should be
SIGNAL(Call(QString))
You connect a signal to a slot, i.e. Call to Respond
Upvotes: 2