Skip to main content

qtbridge_type_lib/core/qobject/
mod.rs

1// Copyright (C) 2026 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only
3
4pub use cxx_qt::QObject;
5
6#[cxx::bridge]
7mod ffi {
8    unsafe extern "C++" {
9        include!("qtbridge-type-lib/src/core/qobject/cpp/qobject.h");
10        type QObject = crate::QObject;
11        include!("qtbridge-type-lib/src/core/qmetaobject/cpp/qmetaobject.h");
12        type QMetaObject = crate::QMetaObject;
13        include!("qtbridge-type-lib/src/core/qvariant/cpp/qvariant.h");
14        type QVariant = crate::QVariant;
15    }
16    #[allow(clippy::missing_safety_doc)]
17    #[namespace = "rust::bridge::qobject"]
18    unsafe extern "C++" {
19        /// Returns a pointer to the meta-object of `obj`.
20        #[rust_name = "meta_object"]
21        fn metaObject(obj: &QObject) -> *const QMetaObject;
22
23        /// Calls C++ `delete` on `obj`.
24        #[rust_name = "delete"]
25        unsafe fn deleteQObject(obj: *mut QObject);
26
27        /// Calls the (virtual) destructor of `obj` without freeing its memory.
28        #[rust_name = "destruct"]
29        unsafe fn destructQObject(obj: *mut QObject);
30
31        /// Returns the value of the property `name`, or an invalid `QVariant` if there is none.
32        fn property(obj: &QObject, name: &str) -> QVariant;
33
34        /// Sets the property `name`. Returns `false` if it is not declared in the meta-object.
35        #[rust_name = "set_property"]
36        unsafe fn setProperty(obj: *mut QObject, name: &str, value: &QVariant) -> bool;
37    }
38}
39
40pub use ffi::{delete, destruct, meta_object, property, set_property};