Results 1 to 4 of 4

Thread: How many copies of Signal parameters

  1. #1
    Join Date
    Jan 2006
    Location
    Berkeley California
    Posts
    109
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How many copies of Signal parameters

    I'm writing a serial port input routine to emit a Signal with a dynamically allocated QByteArray of the line just received. When done with the QByteArray the slot called must delete it. This works fine if there is only 1 slot; if there are multiple slots, are there multiple QByteArrays created, one for each slot, or if only one QByteArray is created how do I handle knowing when I can delete it?

    Thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How many copies of Signal parameters

    Either don't use dynamic allocation for that QByteArray (you won't loose a lot of performance, since Qt container classes are implicitly shared) or use some kind of reference counting (for example boost::shared_ptr or QSharedData and QSharedDataPointer).

  3. #3
    Join Date
    Jan 2006
    Location
    Berkeley California
    Posts
    109
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How many copies of Signal parameters

    Thanks.

    Does your answer mean that there is a distinct instance of the QByteArray created for each Slot?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How many copies of Signal parameters

    Quote Originally Posted by Doug Broadwell View Post
    Does your answer mean that there is a distinct instance of the QByteArray created for each Slot?
    No, it means that QByteArray copies are cheap, so usually you don't have to use pointers.

    Edit: Whether Qt will copy signal parameters or not depends on the connection type. For each queued connection Qt will create an event with a copy of all parameters, but for direct connections it will reuse values passed to the signal.
    Last edited by jacek; 2nd December 2006 at 21:44.

Similar Threads

  1. Module to process application parameters
    By Opilki_Inside in forum General Programming
    Replies: 4
    Last Post: 8th February 2007, 23:26
  2. Replies: 2
    Last Post: 17th May 2006, 21:01
  3. no such signal QListBox::currentChanged()
    By jopie bakker in forum Newbie
    Replies: 2
    Last Post: 2nd March 2006, 15:17
  4. send signal from QCombobox
    By raphaelf in forum Qt Programming
    Replies: 22
    Last Post: 28th February 2006, 14:18
  5. signal slot conection using a string, not a SLOT
    By rianquinn in forum Qt Programming
    Replies: 6
    Last Post: 5th February 2006, 18:52

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.