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
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).
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?
Re: How many copies of Signal parameters
Quote:
Originally Posted by
Doug Broadwell
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.