The setParent(parent) internally calls QCoreApplication::sendEvent(parent, QChildEvent) that implies running in the thread which created the parent object. That is not the case always, and an internal assertion fails in the debug mode.
Backport of core#18948.
with changes from core-gui#587