QMetaObject::invokeMethod pass custom-type called Twice custom-type's copy constructor...
-
@opengpu said in QMetaObject::invokeMethod pass custom-type called Twice custom-type's copy constructor...:
why this works while the slot is const
Why should it not? data will be const in the called slot. It doesn't matter whether it is const or not in the caller.
There is no need to register "const Data&". If Data is registered everything else (const, &, *, ...) is simply an "attribute" for an already known type. It is like with the compiler: if the compiler knows what Data is it knows what const Data& is.
-
@jsulm "const Data&", i think normally it's not safe to pass-by-reference across threads, right?
@opengpu said in QMetaObject::invokeMethod pass custom-type called Twice custom-type's copy constructor...:
i think normally it's not safe to pass-by-reference across threads, right?
Depends who you ask. The chair of the C++ standard committee is of the opinion that as STL uses
const
as implying thread safety* the entire language should conform to that convention. In that case usingcons&
as argument is safe even across threads. On the other hand it's a jungle out there and it's very easy to break that convention so I would not bet my life on thread safety of const references*source: https://herbsutter.com/2013/01/01/video-you-dont-know-const-and-mutable/
-
@jsulm "const Data&", i think normally it's not safe to pass-by-reference across threads, right?
@opengpu said in QMetaObject::invokeMethod pass custom-type called Twice custom-type's copy constructor...:
it's not safe to pass-by-reference across threads, right?
@SGaist already explained in this thread that the parameter is copied when using queued connection between threads, so it IS safe...