QMetaObject::invokeMethod, lambda and duplicated objects...
Unsolved
General and Desktop
-
Hey
Here is a rough idea of the code
testClass::testClass(){ moveToThread(&workThread); /// thread defined as QThread workThread in h. workThread.start() } void testClass::sendMsg(someObject*objPtr){ QMetaObject::invokeMethod(this,[&](){handleObjectData(objPtr);} ,Qt::QueuedConnection); } void testClass::handleObjectData(someObject *objPtr){ qDebug()<<objPtr; /// < this is different object to the one I send above in meta... as if it got copied... why ? }
For some reason when I try to send function/data from MainThread to testClass that is in different thread than mainThread, QT just copies the object... even tho I'm trying to send pointer...
Any ideas?
TIA
-
How did you check? Since you only pass a pointer no object can be copied here.
-
I did print in sendMsg before meta, and after inside
handleObjectData
, I also checked in debug, the object was copied with invalid values, since I didn't implement object copy constructor, not sure. Its weird to me as I should have passed ptr and not obj... weird ! -
Again: you only pass a pointer - there can't be any implicit copy. Please provide a fully working example. Print out the pointer during sendMsg()