PDA

View Full Version : Signal & Slots when pointer to the sender object has been copied



locke
30th July 2010, 15:53
Hi guys, Im sorry if I cannot explain properly the situation

lets get some

the header could be header.h



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


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

Lykurg
30th July 2010, 16:24
Are you sure you have the macro Q_OBJECT in your class B. Is there any error shown when you connect?

locke
30th July 2010, 16:30
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

locke
30th July 2010, 16:34
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.