class Person{
signals:
public slots:
}
class Spy{
public:
void spyOnPerson(Person*)
public slots:
}
//somewhere in application
Person user1, user2, user3
...
//now the spy comes to the scene
Spy spy;
...
spy.spyOnPerson(&user1);
//user1 is some kind of criminal, and i wont to spy on him
//i want spy to hear what user1 hears and what user1 says
//in this exaple spy hears what user1 says, and what user2 and user3 say to user1
//the problem is in assigning person to spy
//i can say
void Spy::spyOnPerson(Person *p){
//but i also need to hear what are the others speaking to user1
//since hear is a slot i cant connect it to anything
//but how can i search for other signals (user2 speak and user3 speak)
//if i just know that hear is a slot and there are signals that call that slot
//of course i can reemit another signal inside hear slot, and i did that
//but it seamed like workaround to insert new signal that actualy executes when a signal (from another user) emits.
//and signals are connectable to signals, and why should i create new signal, just search for the original signal and connect to it...
}
class Person{
signals:
void speak(QString);
public slots:
void hear(QString)
}
class Spy{
public:
void spyOnPerson(Person*)
public slots:
void personHeard(QString)
void personSaid(QString)
}
//somewhere in application
Person user1, user2, user3
...
connect(&user1, speak(QString), &user2 hear(QString);
connect(&user2, speak(QString), &user1 hear(QString);
connect(&user3, speak(QString), &user1 hear(QString);
//now the spy comes to the scene
Spy spy;
...
spy.spyOnPerson(&user1);
//user1 is some kind of criminal, and i wont to spy on him
//i want spy to hear what user1 hears and what user1 says
//in this exaple spy hears what user1 says, and what user2 and user3 say to user1
//the problem is in assigning person to spy
//i can say
void Spy::spyOnPerson(Person *p){
connect(p, speak(QString), this, personSaid(QString);
//but i also need to hear what are the others speaking to user1
connect(p, hear(QString), this personHeard(QString);
//since hear is a slot i cant connect it to anything
//but how can i search for other signals (user2 speak and user3 speak)
//if i just know that hear is a slot and there are signals that call that slot
//of course i can reemit another signal inside hear slot, and i did that
//but it seamed like workaround to insert new signal that actualy executes when a signal (from another user) emits.
//and signals are connectable to signals, and why should i create new signal, just search for the original signal and connect to it...
}
To copy to clipboard, switch view to plain text mode
Bookmarks