Unsolved When using asynchroneous calls QMetaObject::invokeMethod argumnts ae copied?
-
void setProfileImage(const QPixmap &t_profileImage) { chargeImageProvider(t_profileImage); QMetaObject::invokeMethod(StorageWorker::instance(), "setProfileImage", Q_ARG(QPixmap, t_profileImage)); }
I have a piece of code
(StorageWorker::instance()
is in different thread.
It runs async well.
But, how is that possible, becauset_profileImage
is deleated once it comes out of scope ofsetProfileImage(...)
and it is still in use in other thread? Is there copy occures or copy on write? -
@Kofr said in When using asynchroneous calls QMetaObject::invokeMethod argumnts ae copied?:
Is there copy occures or copy on write?
Yes, it does. The argument is copied when it's scheduled through the event loop of the receiving thread. However you mustn't use
QPixmap
across threads, because that class is not reentrant; useQImage
for this. -
@kshegunov yes, I am already refactoring it. Thank you. is there any ref to docs about copying?
-
It's hinted here [1] and also this [2] article makes it explicit.
[1]: http://doc.qt.io/qt-5/threads-qobject.html
[2]: https://woboq.com/blog/how-qt-signals-slots-work-part3-queuedconnection.html