Skip to content

Commit 627a8a6

Browse files
Add qobject extension trait
- cxx-qt-lib trait for additional qobject wrappers - adds first signal blockSignals
1 parent 3c6dbf1 commit 627a8a6

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

crates/cxx-qt-lib/build.rs

+1
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ fn main() {
151151
"core/qmarginsf",
152152
"core/qmodelindex",
153153
"core/qpersistentmodelindex",
154+
"core/qobject",
154155
"core/qpoint",
155156
"core/qpointf",
156157
"core/qrect",

crates/cxx-qt-lib/src/core/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
// SPDX-License-Identifier: MIT OR Apache-2.0
55

66
mod qbytearray;
7+
78
pub use qbytearray::QByteArray;
89

910
mod qcoreapplication;
@@ -44,6 +45,9 @@ pub use cxx_qt::{QMetaObjectConnection, QMetaObjectConnectionGuard};
4445
mod qmodelindex;
4546
pub use qmodelindex::QModelIndex;
4647

48+
mod qobject;
49+
pub use qobject::QObjectExt;
50+
4751
mod qpersistentmodelindex;
4852
pub use qpersistentmodelindex::QPersistentModelIndex;
4953

crates/cxx-qt-lib/src/core/qobject.rs

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// SPDX-FileCopyrightText: 2025 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
2+
// SPDX-FileContributor: Ben Ford <[email protected]>
3+
//
4+
// SPDX-License-Identifier: MIT OR Apache-2.0
5+
6+
use cxx_qt::QObject;
7+
use std::pin::Pin;
8+
9+
#[cxx_qt::bridge]
10+
mod ffi {
11+
unsafe extern "C++" {
12+
#[rust_name = "QObjectExternal"]
13+
type QObject;
14+
15+
#[cxx_name = "blockSignals"]
16+
pub fn blockSignalsQObject(self: Pin<&mut QObjectExternal>, block: bool) -> bool;
17+
}
18+
}
19+
20+
use ffi::QObjectExternal;
21+
22+
pub trait QObjectExt {
23+
fn block_signals(self: Pin<&mut Self>, block: bool) -> bool;
24+
}
25+
26+
fn cast(obj: Pin<&mut QObject>) -> Pin<&mut QObjectExternal> {
27+
unsafe {
28+
let mut_ptr = obj.get_unchecked_mut() as *mut QObject as *mut QObjectExternal;
29+
Pin::new_unchecked(&mut *mut_ptr)
30+
}
31+
}
32+
33+
impl QObjectExt for QObject {
34+
fn block_signals(self: Pin<&mut Self>, block: bool) -> bool {
35+
cast(self).blockSignalsQObject(block)
36+
}
37+
}

0 commit comments

Comments
 (0)