-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: book: rewrite various sections for 0.6
- Loading branch information
1 parent
3d9b13a
commit 542b123
Showing
38 changed files
with
712 additions
and
452 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<!-- | ||
SPDX-FileCopyrightText: 2023 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]> | ||
SPDX-FileContributor: Andrew Hayzen <[email protected]> | ||
SPDX-License-Identifier: MIT OR Apache-2.0 | ||
--> | ||
|
||
# Attributes | ||
|
||
## namespace | ||
|
||
The C++ namespace which to emit `extern "RustQt"` items and the namespace to find `extern "C++Qt"` items. | ||
|
||
An item will inherit the namespace specified on it's surrounding `extern` block if any, | ||
otherwise the namespace specified with the top level `cxx_qt::bridge` attribute, if any, will be used. | ||
|
||
```rust,ignore,noplayground | ||
{{#include ../../../examples/qml_features/rust/src/threading.rs:book_namespace_macro}} | ||
``` | ||
|
||
> Note that `#[namespace = "..."]` may not work on all items, | ||
> we hope to improve this in future this support in the future. | ||
## cxx_name and rust_name | ||
|
||
The `#[cxx_name = "..."]` attribute replaces the name that C++ should use for this item. | ||
|
||
The `#[rust_name = "..."]` attribute replaces the name that Rust should use for this item. | ||
|
||
> Note that `#[cxx_name = "..."]` and `#[rust_name = "..."]` may not work on all items, | ||
> we hope to improve this in future this support in the future. | ||
If no `#[cxx_name = "..."]` or `#[rust_name = "..."]` is specified, CXX-Qt will perform an automatic conversion to function names as specified in the table below. | ||
|
||
| | Rust | C++ | | ||
|------------------|------------|-----------| | ||
| `extern "C++Qt"` | - | camelCase | | ||
| `extern "RustQt"`| - | camelCase | | ||
|
||
> Note that in some cases `snake_case` conversions may occur for generated functions in Rust (eg `on_<signal>`). | ||
> Note that this table may change to the following conversions in the future. | ||
> | ||
> | | Rust | C++ | | ||
> |------------------|------------|-----------| | ||
> | `extern "C++Qt"` | snake_case | - | | ||
> | `extern "RustQt"`| - | camelCase | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<!-- | ||
SPDX-FileCopyrightText: 2023 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]> | ||
SPDX-FileContributor: Andrew Hayzen <[email protected]> | ||
SPDX-License-Identifier: MIT OR Apache-2.0 | ||
--> | ||
|
||
# extern "C++Qt" | ||
|
||
- [QObjects](#qobjects) | ||
- [Methods](#methods) | ||
- [Signals](#signals) | ||
|
||
```rust,ignore,noplayground | ||
#[cxx_qt::bridge] | ||
mod ffi { | ||
extern "C++Qt" { | ||
} | ||
} | ||
``` | ||
|
||
The `extern "C++Qt"` section of a CXX-Qt bridge declares Qt types and signatures to be made available to Rust, | ||
and gives the paths of the headers which contain the corresponding Qt declarations. | ||
|
||
A bridge module may contain zero or more `extern "C++Qt"` blocks. | ||
|
||
This complements the [`extern "C++"` CXX section](https://cxx.rs/extern-c++.html) | ||
but allows for declaring Qt specific features on C++ types. | ||
|
||
## QObjects | ||
|
||
Types defined in C++ that are made available to Rust, but only behind an indirection. | ||
|
||
This is the same as [CXX Opaque C++ types](https://cxx.rs/extern-c++.html#opaque-c-types). | ||
|
||
```rust,ignore,noplayground | ||
#[cxx_qt::bridge] | ||
mod ffi { | ||
extern "C++Qt" { | ||
include!(<QtWidgets/QPushButton>); | ||
type QPushButton; | ||
} | ||
} | ||
``` | ||
|
||
<!-- | ||
TODO: use a real example from qml_features once closure support lands | ||
--> | ||
|
||
## Methods | ||
|
||
Methods can be specified on the Qt type in the same way as [`extern "RustQt"` blocks](./extern_rustqt.md#methods). | ||
|
||
This is the same as [CXX Functions and member functions](https://cxx.rs/extern-c++.html#functions-and-member-functions). | ||
|
||
```rust,ignore,noplayground | ||
#[cxx_qt::bridge] | ||
mod ffi { | ||
unsafe extern "C++" { | ||
include!("cxx-qt-lib/qstring.h"); | ||
type QString = cxx_qt_lib::QString; | ||
} | ||
extern "C++Qt" { | ||
include!(<QtWidgets/QPushButton>); | ||
type QPushButton; | ||
fn text(self: &QPushButton) -> QString; | ||
fn setText(self: Pin<&mut QPushButton>, text: &QString); | ||
} | ||
} | ||
``` | ||
|
||
<!-- | ||
TODO: use a real example from qml_features once closure support lands | ||
--> | ||
|
||
## Signals | ||
|
||
Signals can be specified on the Qt type in the same way as [`extern "RustQt"` blocks](./extern_rustqt.md#signals). | ||
|
||
```rust,ignore,noplayground | ||
#[cxx_qt::bridge] | ||
mod ffi { | ||
extern "C++Qt" { | ||
include!(<QtWidgets/QPushButton>); | ||
type QPushButton; | ||
#[qsignal] | ||
fn clicked(self: Pin<&mut QPushButton>, checked: bool); | ||
} | ||
} | ||
``` | ||
|
||
This then causes CXX-Qt to generate Rust methods to connect to the `#[qsignal]` with a closure, | ||
in the same way as a `#[qsignal]` in a [`extern "RustQt"` block](./extern_rustqt.md#signals). | ||
|
||
> Note using `pub(self)` as the visibility of the signal | ||
> allows for declaring private signals | ||
<!-- | ||
TODO: use a real example from qml_features once closure support lands | ||
--> |
Oops, something went wrong.