According to this answer, Qt just replaces const references with copies.
EDIT: Apparently not always the case… I just did a basic test program with one thread, and the reference was passed correctly. Its const-ness remained intact, as well. Anyways, yes, you do need to be wary of the variable going out of scope, plus you can’t send references across threads this way. If you do, only copies will be passed.
To answer the questions in the comments of your example, yes, it will work regardless of whether it’s a direct or queued connection. If it’s a direct connection, it will work because someSlot()
will be executed before someFunction()
finishes; if it’s a queued connection, it will work because test
will be copied instead of passed by reference.