Results 1 to 5 of 5

Thread: signal/slots and dynamic objects

  1. #1
    Join Date
    Aug 2013
    Posts
    17
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default signal/slots and dynamic objects

    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)

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: signal/slots and dynamic objects

    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.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: signal/slots and dynamic objects

    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.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  4. #4
    Join Date
    Aug 2013
    Posts
    17
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: signal/slots and dynamic objects

    Quote Originally Posted by high_flyer View Post
    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..

  5. #5
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: signal/slots and dynamic objects

    Quote Originally Posted by stingray View Post
    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.

    Quote Originally Posted by stingray View Post
    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.

    Quote Originally Posted by stingray View Post
    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,
    _

Similar Threads

  1. Replies: 5
    Last Post: 19th February 2013, 15:49
  2. Replies: 3
    Last Post: 25th September 2011, 14:44
  3. Dynamic objects without identifier...
    By Bill in forum Newbie
    Replies: 7
    Last Post: 18th August 2009, 15:17
  4. Load objects from dynamic library
    By Trok in forum Qt Programming
    Replies: 10
    Last Post: 17th July 2009, 20:04
  5. Lumina GLSL IDE based on QtScript and dynamic Objects
    By oc2k1 in forum Qt-based Software
    Replies: 0
    Last Post: 12th August 2008, 04:12

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.