PDA

View Full Version : <Solved> Pointer to Calling class is needed



Casisto
22nd August 2015, 16:52
Hi there,

I've a problem with the old topic "Signal from one class to another class".

To clearify my situation:

I have A which calls B (a modal QDialog, so it is without parent). B has a button, when pressed a function in A is calling, this way works. But the other way round I have the problem...

I initialize B like this:


b = new B();
and later in the "openFunction":

b->setFixedSize(b->minimumSize());
testbshow();

and now, in B I want this:

connect(A, SIGNAL(CallB()), this, SLOT(FunctionB()));

Because B should be Modal I can't do anything like this (maybe, I'm only don't know how I get B modal with this line):

b = new B(this);

I hope someone has a idea what I can do, so that B can get a signal from A.

-casisto

anda_skoa
22nd August 2015, 18:00
I have A which calls B (a modal QDialog, so it is without parent).

What does modality have to do with parent/child relationship?


and now, in B I want this:

connect(A, SIGNAL(CallB()), this, SLOT(FunctionB()));

Isn't it way easier to do the connect inside A, where you have both a pointer to A and B?
E.g. right after creating B

Cheers,
_

Casisto
22nd August 2015, 18:56
Thanks so much!

I didn't know that I can do this so. I ever thought the connect has to been in the class where the function is declared.

anda_skoa
22nd August 2015, 19:34
I didn't know that I can do this so. I ever thought the connect has to been in the class where the function is declared.
No, that's the beauty of signal/slots.
Neither the sender nor the receiver need to know about the other or the connect, the connection can be done by any code that knows both objects.

Cheers,
_