PDA

View Full Version : signal/slots and dynamic objects



stingray
23rd January 2017, 13:31
so a dynamic object and connect.

does it matter if i connect it at a temporary pointer (when i create the object) or at the storage point where i store the object?

it really doesnt matter, its just good to know. (i intend to connect when puting the object into the storage point)

high_flyer
23rd January 2017, 16:46
The question doesn't make much sense, it gives the impression you are not really aware of what connect does, and/or what is a pointer.
In what way do you mean that is should "matter"?
The connect statement takes pointers of the sender object and the receiver object.
It only "matters" as long as the sender is alive, the receiver is alive as well otherwise a slot maybe invoked on a not valid pointer. (I don't know if Qt is smart enough to delete connections if a receiver is deleted, it might though, in which case even that scenario is "safe").
How you deliver the pointer to the connect() statement is not of importance nor if its a temporary pointer variable or not.

d_stranz
23rd January 2017, 17:02
I don't know if Qt is smart enough to delete connections if a receiver is deleted, it might though, in which case even that scenario is "safe"

Yes, Qt is "smart enough". If either side of a connection is deleted, then all connections to that side are disconnected.

stingray
23rd January 2017, 17:50
The question doesn't make much sense, it gives the impression you are not really aware of what connect does, and/or what is a pointer.
In what way do you mean that is should "matter"?
The connect statement takes pointers of the sender object and the receiver object.
It only "matters" as long as the sender is alive, the receiver is alive as well otherwise a slot maybe invoked on a not valid pointer. (I don't know if Qt is smart enough to delete connections if a receiver is deleted, it might though, in which case even that scenario is "safe").
How you deliver the pointer to the connect() statement is not of importance nor if its a temporary pointer variable or not.

a pointer is a object that points to a place in memory where the object is stored.
is the definition if i got pointer a & b of the same type.

if i dynamicially allocate a, then connect a, assign the adress in pointer b, and null down pointer a, does qt use the memory location or the object pointer a (thats a null ptr right now) so ptr b will get the signal?

i think its the pointer it uses and not the memory location, but i want to be sure.

for my use right now i assume its the pointer object and not the memory allocation it hooks to.

the signal slot system and the moc process i cant say i know like the back of my hand..

anda_skoa
24th January 2017, 09:11
if i dynamicially allocate a, then connect a, assign the adress in pointer b, and null down pointer a, does qt use the memory location or the object pointer a (thats a null ptr right now) so ptr b will get the signal?

The pointer is just a handle to the object, setting it to null_ptr does not affect the object in anyway.
If you assign a pointer to another pointer, then both are independent handles to the same object.



i think its the pointer it uses and not the memory location, but i want to be sure.

Neither, it uses the object that is pointed to.



for my use right now i assume its the pointer object and not the memory allocation it hooks to.

The other way around.

The pointer "object" is totally irrelevant, the only thing that matters is the memory location (object instance) the pointer refers/points to.

Cheers,
_