Skip to content

Commit cc68a3e

Browse files
committed
Additional QVariant conversions
1 parent b49a149 commit cc68a3e

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-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) }

qttypes/src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,15 @@ impl From<QUrl> for QVariant {
749749
})
750750
}
751751
}
752+
753+
impl From<QPointF> for QVariant {
754+
fn from(a: QPointF) -> QVariant {
755+
cpp!(unsafe [a as "QPointF"] -> QVariant as "QVariant" {
756+
return QVariant(a);
757+
})
758+
}
759+
}
760+
752761
impl From<QVariantList> for QVariant {
753762
/// Wrapper around [`QVariant(const QVariantList &)`][ctor] constructor.
754763
///
@@ -829,6 +838,7 @@ impl From<bool> for QVariant {
829838
})
830839
}
831840
}
841+
832842
impl<'a, T> From<&'a T> for QVariant
833843
where
834844
T: Into<QVariant> + Clone,

0 commit comments

Comments
 (0)