[Interest] QMetaMethod::invoke / Q_ARG with a temporary

Giuseppe D'Angelo giuseppe.dangelo at kdab.com
Mon May 7 22:12:14 CEST 2018


Il 07/05/2018 20:24, Christian Ehrlicher ha scritto:
> I did not found a hint int the documentation about this behavior.
> Therefore my question - should this work for a queued connection or not?
> At least msvc2017 and gcc 4.8 don't like it when compiling with -O2...

The documentation doesn't talk about QArgument, but about Q_ARG and 
Q_RETURN_ARG, which is what you should use.

(Under the hood, the problem is that QArgument simply stores a pointer 
to your variable. If that variable is a temporary, that pointer becomes 
immediately dangling. For this reason, do not store what Q_ARG builds, 
e.g. in an variable declared auto!)

HTH,
-- 
Giuseppe D'Angelo | giuseppe.dangelo at kdab.com | Senior Software Engineer
KDAB (France) S.A.S., a KDAB Group company
Tel. France +33 (0)4 90 84 08 53, http://www.kdab.com
KDAB - The Qt, C++ and OpenGL Experts

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4007 bytes
Desc: Firma crittografica S/MIME
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20180507/9fc1ee4b/attachment.bin>


More information about the Interest mailing list