[−][src]Struct qt_core::QBox
An owning pointer for QObject
-based objects.
QBox
will delete its object on drop if it has no parent. If the object has a parent,
it's assumed that the parent is responsible for deleting the object, as per Qt ownership system.
Additionally, QBox
will be automatically set to null when the object is deleted, similar
to QMutPtr
(or QPointer<T>
in C++). QBox
will not attempt to delete null pointers.
Note that dereferencing a null QBox
will panic, so if it's known that the object may
already have been deleted, you should use is_null()
, as_mut_ref()
,
or a similar method to check
if the object is still alive before calling its methods.
Unlike CppBox
(which is non-nullable), QBox
is permitted to contain a null pointer because
even if a non-null pointer is provided when constructing QBox
, it will become null
automatically if the object is deleted.
To prevent the object from being deleted, convert QBox
to another type of pointer using
into_q_mut_ptr()
or into_ptr()
. Alternatively, setting a parent for the object will prevent
QBox
from deleting it.
To make sure the object is deleted regardless of its parent, convert QBox
to CppBox
using
into_box()
.
Safety
QBox
has the same safety issues as QMutPtr
. See QMutPtr
documentation.
Methods
impl<T: StaticUpcast<QObject> + CppDeletable> QBox<T>
[src]
pub unsafe fn from_q_mut_ptr(target: QMutPtr<T>) -> Self
[src]
pub unsafe fn new(target: impl CastInto<MutPtr<T>>) -> Self
[src]
Creates a QBox
from a MutPtr
.
Safety
target
must be either a valid pointer to an object or a null pointer.
See type level documentation.
pub unsafe fn from_raw(target: *mut T) -> Self
[src]
Creates a QBox
from a raw pointer.
Safety
target
must be either a valid pointer to an object or a null pointer.
See type level documentation.
pub unsafe fn null() -> Self
[src]
Creates a null pointer.
Note that you can also use NullPtr
to specify a null pointer to a function accepting
impl CastInto<MutPtr<_>>
. Unlike MutPtr
, NullPtr
is not a generic type, so it will
not cause type inference issues.
Note that accessing the content of a null QBox
through Deref
or DerefMut
will result
in a panic.
Safety
Null pointers must not be dereferenced. See type level documentation.
pub unsafe fn is_null(&self) -> bool
[src]
Returns true if the pointer is null.
pub unsafe fn as_mut_ptr(&mut self) -> MutPtr<T>
[src]
pub unsafe fn as_ptr(&self) -> Ptr<T>
[src]
pub unsafe fn as_raw_ptr(&self) -> *const T
[src]
pub unsafe fn as_mut_raw_ptr(&mut self) -> *mut T
[src]
pub unsafe fn as_ref(&self) -> Option<Ref<T>>
[src]
Returns the content as a const Ref
. Returns None
if self
is a null pointer.
Safety
See type level documentation.
pub unsafe fn as_mut_ref(&mut self) -> Option<MutRef<T>>
[src]
Returns the content as a MutRef
. Returns None
if self
is a null pointer.
Safety
See type level documentation.
pub unsafe fn static_upcast_mut<U>(&mut self) -> QMutPtr<U> where
T: StaticUpcast<U>,
U: StaticUpcast<QObject>,
[src]
T: StaticUpcast<U>,
U: StaticUpcast<QObject>,
Converts the pointer to the base class type U
.
Safety
This operation is safe as long as self
is valid or null. See type level documentation.
pub unsafe fn static_upcast<U>(&self) -> QPtr<U> where
T: StaticUpcast<U>,
U: StaticUpcast<QObject>,
[src]
T: StaticUpcast<U>,
U: StaticUpcast<QObject>,
Converts the pointer to the base class type U
.
Safety
This operation is safe as long as self
is valid or null. See type level documentation.
pub unsafe fn static_downcast_mut<U>(&mut self) -> QMutPtr<U> where
T: StaticDowncast<U>,
U: StaticUpcast<QObject>,
[src]
T: StaticDowncast<U>,
U: StaticUpcast<QObject>,
Converts the pointer to the derived class type U
.
It's recommended to use dynamic_cast
instead because it performs a checked conversion.
Safety
This operation is safe as long as self
is valid and it's type is U
or inherits from U
,
of if self
is a null pointer. See type level documentation.
pub unsafe fn static_downcast<U>(&self) -> QPtr<U> where
T: StaticDowncast<U>,
U: StaticUpcast<QObject>,
[src]
T: StaticDowncast<U>,
U: StaticUpcast<QObject>,
Converts the pointer to the derived class type U
.
It's recommended to use dynamic_cast
instead because it performs a checked conversion.
Safety
This operation is safe as long as self
is valid and it's type is U
or inherits from U
,
of if self
is a null pointer. See type level documentation.
pub unsafe fn dynamic_cast_mut<U>(&mut self) -> QMutPtr<U> where
T: DynamicCast<U>,
U: StaticUpcast<QObject>,
[src]
T: DynamicCast<U>,
U: StaticUpcast<QObject>,
Converts the pointer to the derived class type U
. Returns None
if the object's type
is not U
and doesn't inherit U
.
Safety
This operation is safe as long as self
is valid or null. See type level documentation.
pub unsafe fn dynamic_cast<U>(&self) -> QPtr<U> where
T: DynamicCast<U>,
U: StaticUpcast<QObject>,
[src]
T: DynamicCast<U>,
U: StaticUpcast<QObject>,
Converts the pointer to the derived class type U
. Returns None
if the object's type
is not U
and doesn't inherit U
.
Safety
This operation is safe as long as self
is valid or null. See type level documentation.
pub unsafe fn into_box(self) -> Option<CppBox<T>>
[src]
Converts this pointer to a CppBox
. Returns None
if self
is a null pointer.
Unlike QBox
, CppBox
will always delete the object when dropped.
Safety
CppBox
will attempt to delete the object on drop. If something else also tries to
delete this object before or after that, the behavior is undefined.
See type level documentation.
pub unsafe fn into_q_mut_ptr(self) -> QMutPtr<T>
[src]
pub unsafe fn into_q_ptr(self) -> QPtr<T>
[src]
pub unsafe fn into_ptr(self) -> MutPtr<T>
[src]
pub unsafe fn into_raw_ptr(self) -> *mut T
[src]
Trait Implementations
impl<'a, T: StaticUpcast<QObject> + CppDeletable> AsReceiver for &'a QBox<T> where
T: AsReceiver,
[src]
T: AsReceiver,
type Arguments = <T as AsReceiver>::Arguments
fn as_receiver(&self) -> Receiver<Self::Arguments>
[src]
impl<'a, T, U> CastFrom<&'a QBox<U>> for Ptr<T> where
U: StaticUpcast<T> + StaticUpcast<QObject> + CppDeletable,
[src]
U: StaticUpcast<T> + StaticUpcast<QObject> + CppDeletable,
impl<'a, T, U> CastFrom<&'a mut QBox<U>> for MutPtr<T> where
U: StaticUpcast<T> + StaticUpcast<QObject> + CppDeletable,
[src]
U: StaticUpcast<T> + StaticUpcast<QObject> + CppDeletable,
impl<T: StaticUpcast<QObject> + CppDeletable> Debug for QBox<T>
[src]
impl<T: StaticUpcast<QObject> + CppDeletable> Deref for QBox<T>
[src]
Allows to call member functions of T
and its base classes directly on the pointer.
Panics if the pointer is null.
impl<T: StaticUpcast<QObject> + CppDeletable> DerefMut for QBox<T>
[src]
Allows to call member functions of T
and its base classes directly on the pointer.
Panics if the pointer is null.
impl<T: StaticUpcast<QObject> + CppDeletable> Drop for QBox<T>
[src]
Auto Trait Implementations
impl<T> RefUnwindSafe for QBox<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> !Send for QBox<T>
impl<T> !Sync for QBox<T>
impl<T> Unpin for QBox<T>
impl<T> UnwindSafe for QBox<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> CastInto<U> for T where
U: CastFrom<T>,
[src]
U: CastFrom<T>,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> StaticUpcast<T> for T
[src]
unsafe fn static_upcast(ptr: Ptr<T>) -> Ptr<T>
[src]
unsafe fn static_upcast_mut(ptr: MutPtr<T>) -> MutPtr<T>
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,