Skip to content

Commit 96365ba

Browse files
Update book and docs
1 parent e457080 commit 96365ba

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

book/src/getting-started/2-our-first-cxx-qt-module.md

+7
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,13 @@ These functions then need to be implemented **outside** the bridge using `impl q
143143
{{#include ../../../examples/qml_minimal/rust/src/cxxqt_object.rs:book_rustobj_invokable_impl}}
144144
```
145145

146+
### Inlining the self receiver
147+
148+
If an `extern "RustQt"` block contains exactly one `QObject`, the self type of methods can be inferred.
149+
For instance, in a block with multiple or no `QObject`s, a function like `foo(&self)` or `foo(self: Pin<&mut Self>)`
150+
would not compile, but will compile with the `Self` type set to that blocks `QObject`.
151+
This is how CXX [handles it](https://cxx.rs/extern-rust.html) (see the Methods heading).
152+
146153
This setup is a bit unusual, as the type `qobject::MyObject` is actually defined in C++.
147154
However, it is still possible to add member functions to it in Rust and then expose them back to C++.
148155
This is the usual workflow for `QObject`s in CXX-Qt.

crates/cxx-qt-gen/src/parser/cxxqtdata.rs

+5
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ impl ParsedCxxQtData {
6868
}
6969
}
7070

71+
/// Inline any `Self` types in the methods signatures with the Ident of a qobject passed in
72+
///
73+
/// If there are unresolved methods in the list, but inline is false, it will error,
74+
/// as the self inlining is only available if there is exactly one `QObject` in the block,
75+
/// and this indicates that no inlining can be done, but some `Self` types were present.
7176
fn try_inline_self_types(
7277
inline: bool,
7378
type_to_inline: &Option<Ident>,

0 commit comments

Comments
 (0)