use cxx::let_cxx_string;
use crate::ffi;
pub struct QmlEngine {
ptr: *mut ffi::QQmlApplicationEngine,
}
impl QmlEngine {
pub fn new() -> Self {
let ptr = unsafe { ffi::QQmlApplicationEngine_new() };
debug_assert!(!ptr.is_null(), "QQmlApplicationEngine_new returned null");
Self { ptr }
}
pub fn raw_ptr(&self) -> *mut std::ffi::c_void {
self.ptr as *mut std::ffi::c_void
}
pub fn load(&self, qml_path: &str) {
debug_assert!(!self.ptr.is_null(), "QmlEngine::load on null pointer");
let_cxx_string!(c_path = qml_path);
unsafe {
ffi::QQmlApplicationEngine_load(self.ptr, &c_path);
}
}
}
impl Default for QmlEngine {
fn default() -> Self {
Self::new()
}
}
impl Drop for QmlEngine {
fn drop(&mut self) {
if self.ptr.is_null() {
return;
}
unsafe { ffi::QQmlApplicationEngine_delete(self.ptr) };
self.ptr = std::ptr::null_mut();
}
}