Skip to content

Commit

Permalink
Move qt-gui into workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
LeonMatthesKDAB committed Nov 17, 2023
1 parent 9b49732 commit 1e0d2c7
Show file tree
Hide file tree
Showing 15 changed files with 876 additions and 449 deletions.
6 changes: 2 additions & 4 deletions book/src/tutorial/library/cli-with-library.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ Let's now use the library we created in our small CLI app.
```toml
[dependencies]
rustagram2 = "2"

[dependencies.image-manipulation]
path = "../image-manipulation"
image-manipulation = { path = "../image-manipulation" }
```

✅ Recreate parts of the main function:
Expand Down Expand Up @@ -57,4 +55,4 @@ std::fs::write(output, manipulated_image).unwrap();

Some ideas on what to do next:

* Instead of unwrapping all errors, handle `Result` otherwise
* Instead of unwrapping all errors, handle `Result` otherwise
25 changes: 20 additions & 5 deletions book/src/tutorial/qt-gui/build-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,20 @@ CXX-Qt provides helper libraries that make it easy for the Rust build system to

The goal for now is to create a simple program that just launches an Qt/QML application.

✅ Create a new Rust application
✅ In the workspace create a new Rust application
```console
cargo new --bin qt-gui
```

✅ Add the new crate to the workspace
```toml
[workspace]
members = ["cli", "image-manipulation", "qt-gui"]
resolver = "2"
```

✅ Then enter our new crate
```console
cargo new qt-gui
cd qt-gui
```

Expand All @@ -27,7 +38,9 @@ ApplicationWindow {
✅ Add dependencies to the `Cargo.toml` file
```toml
[dependencies]
rustagram2="2"
rustagram2="*"
image-manipulation = { path = "../image-manipulation" }

cxx="1.0.95"
cxx-qt = { git="https://github.com/LeonMatthesKDAB/cxx-qt", branch="qimage" }
cxx-qt-lib = { git="https://github.com/LeonMatthesKDAB/cxx-qt", branch="qimage" }
Expand All @@ -38,7 +51,7 @@ cxx-qt-build = { git="https://github.com/LeonMatthesKDAB/cxx-qt", branch="qimage
```

```diff
- At the time of writing (15.11.2023), CXX-Qt 0.6 hasn't been released yet.
- At the time of writing (17.11.2023), CXX-Qt 0.6 hasn't been released yet.
- To keep the training material up-to-date with the new API introduced in version 0.6,
- we'll use the version from Github for now.
- The training material on Github will be updated as soon as version 0.6 is released!
Expand All @@ -53,7 +66,9 @@ cxx-qt-build = { git="https://github.com/LeonMatthesKDAB/cxx-qt", branch="qimage

```toml
[dependencies]
rustagram2="2"
rustagram2="*"
image-manipulation = { path = "../image-manipulation" }

cxx="1.0.95"
cxx-qt="0.6"
cxx-qt-lib="0.6"
Expand Down
8 changes: 4 additions & 4 deletions book/src/tutorial/qt-gui/qquickpainteditem.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ Before you do anything else, make sure to

Because we will be using the `#[cxx_qt::bridge]` macro, we have to register this file twice.

1. In the `src/main.rs` file, add a line: `pub mod image_painter;`\
This registers the new file as a module of our application and makes it known to Cargo.
2. In the `build.rs` file, add the file to the list of rust_files of the QmlModule.\
This registers the new file with CXX-Qt.
1. In the `src/main.rs` file, add a line: `pub mod image_painter;`
* This registers the new file as a module of our application and makes it known to Cargo.
2. In the `build.rs` file, add the file to the list of rust_files of the QmlModule.
* This registers the new file with CXX-Qt.\
It tells CXX-Qt to generate a C++ class from it, run moc and link the resulting class into our application.
This is only necessary because we want to use CXX-Qt within the file.
Doing this second step is not necessary for a normal Rust module.
Expand Down
2 changes: 1 addition & 1 deletion book/src/tutorial/qt-gui/rust-implementation.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ The resulting application should look like this:

![The final application, showing the picture of a skyline that has been filtered using the "lofi" filter](./qt-gui-skyline.png)

✅ Check out the [full example code](https://github.com/ferrous-systems/qt-training-2023/tree/main/crates/qt-gui) and compare it with your implementation
✅ Check out the [full example code](https://github.com/ferrous-systems/qt-training-2023/tree/main/crates/with-workspace/) and compare it with your implementation

[QQuickPaintedItem]: https://doc.qt.io/qt-6/qquickpainteditem-members.html
[CXX-Qt book]: https://docs.rs/cxx-qt-lib/latest/cxx_qt_lib/
Loading

0 comments on commit 1e0d2c7

Please sign in to comment.