Signal & Slots when pointer to the sender object has been copied
Hi guys, Im sorry if I cannot explain properly the situation
lets get some
the header could be header.h
Code:
class A:
{
signals:
MySignal();
};
class MainWindow
{
A * a:
// More things
//........
};
class B
{
public:
B(A* a);
private slots:
myDummySlotInB()
private:
A* my_a;
}
lets see supose that the cpp file contains
Code:
MainWindow::MainWindow()
{
connect(a, SIGNAL(MySignal()), this, SLOT(dummySlot()));
//......
}
B::B(A* a)
{
my_a = a;
connect(my_a, SIGNAL(MySignal()), this, SLOT(dummySlotInB()));
}
Why the connection in the constructor of MainWindow is working properly, and no the connection in the constructor of B?. I just copied the pointer, so my_a is poiting to (*a) as well. Then, if the pointer a emits the signal, Why I cannot catch it in B?
Thanks
Re: Signal & Slots when pointer to the sender object has been copied
Are you sure you have the macro Q_OBJECT in your class B. Is there any error shown when you connect?
Re: Signal & Slots when pointer to the sender object has been copied
The class B has the macro Q_OBJECT (it also send signals) and there is no compiling problem. I can execute the app but the connection in B doesnt work
Re: Signal & Slots when pointer to the sender object has been copied
Solved: There was a small diference in the name of the SLOT. It lets you complile but there is no slot to catch the signal.