Open
Description
Currently, QObjectExt::set_parent accepts a parent: &QObject
argument, which it then converts to a mutable pointer:
cxx-qt/crates/cxx-qt-lib/src/core/qobject.rs
Lines 94 to 99 in 511ec27
Is this really safe? QObject::setParent() requires a mutable pointer on Qt's side, and its implementation mutates the parent by appending the object to its list of children. It also triggers the ChildAdded event on the parent, which may perform arbitrary code in its event handler.
I would have expected something more like this:
fn set_parent<T>(self: Pin<&mut Self>, parent: Option<Pin<&mut T>>)
where
T: Upcast<QObject>,
{
unsafe {
let parent = match parent {
Some(parent) => ptr::from_mut(parent.upcast_pin().get_unchecked_mut()).cast(),
None => ptr::null_mut(),
};
cast_pin(self).set_parent(parent);
}
}