Skip to content

Commit 9f82c5f

Browse files
farmaazonogoffart
authored andcommitted
Additional QVariant conversions
1 parent b49a149 commit 9f82c5f

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

qmetaobject/src/lib.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,15 @@ impl<'pin, T: QObject + 'pin> QObjectPinned<'pin, T> {
532532
}
533533
}
534534

535+
impl<'pin, T: QObject + 'pin> From<QObjectPinned<'pin, T>> for QVariant {
536+
fn from(obj: QObjectPinned<'pin, T>) -> Self {
537+
let x = obj.get_or_create_cpp_object();
538+
cpp!(unsafe [x as "QObject *"] -> QVariant as "QVariant" {
539+
return QVariant::fromValue(x);
540+
})
541+
}
542+
}
543+
535544
/// A wrapper around RefCell<T>, whose content cannot be move in memory
536545
pub struct QObjectBox<T: QObject + ?Sized>(Box<RefCell<T>>);
537546

@@ -541,6 +550,12 @@ impl<T: QObject> QObjectBox<T> {
541550
}
542551
}
543552

553+
impl<T: QObject + Default> Default for QObjectBox<T> {
554+
fn default() -> Self {
555+
Self::new(Default::default())
556+
}
557+
}
558+
544559
impl<T: QObject + ?Sized> QObjectBox<T> {
545560
pub fn pinned(&self) -> QObjectPinned<T> {
546561
unsafe { QObjectPinned::new(&self.0) }

0 commit comments

Comments
 (0)