From 0ce1fb0f20dcbd0530b6f29235495fed6d2e47c4 Mon Sep 17 00:00:00 2001 From: Adam Obuchowicz Date: Sat, 24 Apr 2021 22:08:37 +0200 Subject: [PATCH] Additional QVariant conversions --- qmetaobject/src/lib.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/qmetaobject/src/lib.rs b/qmetaobject/src/lib.rs index e71732fa..622c664f 100644 --- a/qmetaobject/src/lib.rs +++ b/qmetaobject/src/lib.rs @@ -532,6 +532,15 @@ impl<'pin, T: QObject + 'pin> QObjectPinned<'pin, T> { } } +impl<'pin, T: QObject + 'pin> From> for QVariant { + fn from(obj: QObjectPinned<'pin, T>) -> Self { + let x = obj.get_or_create_cpp_object(); + cpp!(unsafe [x as "QObject *"] -> QVariant as "QVariant" { + return QVariant::fromValue(x); + }) + } +} + /// A wrapper around RefCell, whose content cannot be move in memory pub struct QObjectBox(Box>); @@ -541,6 +550,12 @@ impl QObjectBox { } } +impl Default for QObjectBox { + fn default() -> Self { + Self::new(Default::default()) + } +} + impl QObjectBox { pub fn pinned(&self) -> QObjectPinned { unsafe { QObjectPinned::new(&self.0) }