Thursday, 15 May 2014

c++ - Qt moveToThread: What resources are brought with the object? -



c++ - Qt moveToThread: What resources are brought with the object? -

say have created qobject a , has fellow member qobject b. (actually, both , b subclasses of qobject, , class has fellow member b b.)

when b created, parent 0 (default). in code, if never set b's parent a, , if phone call movetothread() move a worker thread, will b moved thread too?

if not moved, if phone call b.init() worker thread (the 1 moved a into) utilize new operator create qobject has b parent, next error, right?

qobject: cannot create children parent in different thread

as qt documentation qobject::movetothread states: -

changes thread affinity object , children. object cannot moved if has parent. event processing go on in targetthread.

in case, parent object kid set either passing parent in constructor or calling setparent on child. not an object has pointer object.

in code, if never set b's parent a, , if phone call movetothread() move worker thread, b moved thread too?

so, no, if b's parent not set , phone call movetothread on 'a', 'b' still have original thread affinity.

if not moved, if phone call b.init() worker thread...

if you've moved 'a' , not 'b' worker thread, should not calling b.init straight worker thread. instead, object in worker thread ('a') should emit signal object in original thread phone call b.init connected slot

c++ multithreading qt

No comments:

Post a Comment