View Full Version : How many copies of Signal parameters
Doug Broadwell
2nd December 2006, 20:50
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
jacek
2nd December 2006, 20:57
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).
Doug Broadwell
2nd December 2006, 21:27
Thanks.
Does your answer mean that there is a distinct instance of the QByteArray created for each Slot?
jacek
2nd December 2006, 21:34
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.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.