[Qt-interest] Safety of Passing by Reference with Signals andSlots
Thiago Macieira
thiago.macieira at trolltech.com
Fri May 1 21:58:50 CEST 2009
Will Rutherdale (rutherw) wrote:
>Thanks, that sounds reassuring. It sounds like you're saying it will
>copy my parameter data into the queue on an emit, so I can pass by
>reference and be safe. It sounds like you're saying it allocates a
>QEvent object and frees it, or something equivalent.
That's correct :-)
>Regarding your criteria, my struct would have default copy constructors,
>but had no Q_DECLARE_METATYPE or qRegisterMetaType. I am familiar with
>these names, as I have used them in other parts of the code involving
>QtDBus. However, for the simple emit statements that are used within
>one process to talk to different threads, I have not used them.
They're only necessary for queued emissions, which is your case here,
exactly because Qt needs to copy the arguments.
>When I actually tested the code, it worked. All the data got through.
>There were no warnings or error messages at any stage. What is supposed
>to go wrong if I don't provide Q_DECLARE_METATYPE or qRegisterMetaType?
The signal connection will work without a hitch.
However, the signal emission will cause a warning to be emitted and the
signal will not be delivered.
Please pay attention to the output of your application, especially if
you're on Windows (where by default the output is not visible without
special tools). To catch those cases, I recommend running your application
with the QT_FATAL_WARNINGS environment variable set to 1 while developing.
--
Thiago Macieira - thiago.macieira (AT) nokia.com
Senior Product Manager - Nokia, Qt Software
Sandakerveien 116, NO-0402 Oslo, Norway
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090501/4ae0eb68/attachment.bin
More information about the Qt-interest-old
mailing list