├── templates ├── qt_widgets_cargo │ ├── .gitignore │ ├── Cargo.toml │ ├── README.md │ ├── build.rs │ ├── src │ │ ├── main.rs │ │ ├── implementation.rs │ │ ├── main.cpp │ │ └── main.ui │ └── bindings.json ├── qt_quick │ ├── rust │ │ ├── src │ │ │ ├── lib.rs │ │ │ ├── implementation.rs │ │ │ └── interface.rs │ │ ├── Cargo.toml │ │ └── Cargo.lock │ ├── qml.qrc │ ├── cmake │ │ ├── FindRustQtBindingGenerator.cmake │ │ ├── FindRust.cmake │ │ └── FindCargo.cmake │ ├── README.md │ ├── main.qml │ ├── src │ │ ├── main.cpp │ │ ├── Bindings.h │ │ └── Bindings.cpp │ ├── bindings.json │ ├── MainForm.ui.qml │ └── CMakeLists.txt ├── qt_widgets │ ├── rust │ │ ├── src │ │ │ ├── lib.rs │ │ │ ├── implementation.rs │ │ │ └── interface.rs │ │ ├── Cargo.toml │ │ └── Cargo.lock │ ├── cmake │ │ ├── FindRustQtBindingGenerator.cmake │ │ ├── FindRust.cmake │ │ └── FindCargo.cmake │ ├── README.md │ ├── src │ │ ├── main.cpp │ │ ├── Bindings.h │ │ └── Bindings.cpp │ ├── bindings.json │ └── CMakeLists.txt └── qt_quick_cargo │ ├── qml.qrc │ ├── Cargo.toml │ ├── README.md │ ├── main.qml │ ├── build.rs │ ├── src │ ├── main.rs │ ├── implementation.rs │ └── main.cpp │ ├── bindings.json │ └── MainForm.ui.qml ├── logo.png ├── tests ├── rust_list │ ├── src │ │ ├── lib.rs │ │ └── implementation.rs │ ├── Cargo.toml │ └── Cargo.lock ├── rust_object │ ├── src │ │ ├── lib.rs │ │ ├── implementation.rs │ │ └── interface.rs │ ├── Cargo.toml │ └── Cargo.lock ├── rust_tree │ ├── src │ │ ├── lib.rs │ │ └── implementation.rs │ ├── Cargo.toml │ └── Cargo.lock ├── rust_functions │ ├── src │ │ ├── lib.rs │ │ └── implementation.rs │ ├── Cargo.toml │ └── Cargo.lock ├── rust_list_types │ ├── src │ │ └── lib.rs │ ├── Cargo.toml │ └── Cargo.lock ├── rust_objects │ ├── src │ │ ├── lib.rs │ │ └── implementation.rs │ ├── Cargo.toml │ └── Cargo.lock ├── rust_object_types │ ├── src │ │ └── lib.rs │ ├── Cargo.toml │ └── Cargo.lock ├── test_object.json ├── test_tree.json ├── test_object_rust.h ├── test_list.json ├── test_objects.json ├── test_functions_rust.h ├── test_object_rust.cpp ├── test_object.cpp ├── test_objects_rust.h ├── test_tree.cpp ├── test_tree_rust.h ├── CMakeLists.txt ├── test_functions.json ├── test_list_types.json ├── test_objects.cpp ├── test_object_types.json ├── test_functions.cpp ├── test_list.cpp ├── test_functions_rust.cpp ├── test_objects_rust.cpp ├── test_object_types_rust.h └── test_list_types_rust.h ├── tutorial ├── demo.png ├── demo2.png ├── demo3.png ├── time.png ├── happy_time.png ├── SUMMARY.md └── book.toml ├── .gitignore ├── examples └── todos │ ├── rust │ ├── src │ │ └── lib.rs │ ├── Cargo.toml │ └── Cargo.lock │ ├── todos.png │ ├── qml.qrc │ ├── cmake │ ├── FindRustQtBindingGenerator.cmake │ ├── FindRust.cmake │ └── FindCargo.cmake │ ├── src │ ├── main.cpp │ └── Bindings.h │ ├── README.md │ ├── bindings.json │ └── CMakeLists.txt ├── demo ├── screenshots │ ├── demo.png │ ├── demo2.png │ └── demo3.png ├── rust │ ├── Cargo.toml │ ├── src │ │ ├── lib.rs │ │ └── implementation │ │ │ ├── mod.rs │ │ │ ├── time_series.rs │ │ │ ├── demo.rs │ │ │ └── fibonacci.rs │ └── Cargo.lock ├── Messages.sh ├── resource_file.qrc ├── qml │ ├── FibonacciList.qml │ ├── FibonacciListKirigami.qml │ ├── FibonacciList2.qml │ ├── StyleSwitcher.qml │ ├── StyleSwitcher2.qml │ ├── Fibonacci2.qml │ ├── Fibonacci.qml │ ├── FileTreeView.qml │ ├── demo-qtquick2.qml │ ├── demo-kirigami2.qml │ ├── chart.qml │ ├── demo.qml │ ├── ProcessesTree.qml │ ├── FileTreeView2.qml │ └── FileTreeViewKirigami.qml ├── src │ ├── SortedModel.cpp │ └── SortedModel.h └── CMakeLists.txt ├── AUTHORS ├── design.txt ├── cmake ├── FindRust.cmake └── FindCargo.cmake ├── COPYING.EXCEPTION ├── shell.nix ├── src ├── README.md ├── util.rs ├── bin │ └── rust_qt_binding_generator.rs ├── lib.rs └── configuration_private.rs ├── Cargo.toml ├── docker ├── docker-bash-session.sh └── Dockerfile ├── ChangeLog ├── org.kde.rust_qt_binding_generator.desktop ├── CMakeLists.txt └── poqm ├── zh_TW └── rqbgdemo_qt.po ├── lt └── rqbgdemo_qt.po ├── ja └── rqbgdemo_qt.po └── ru └── rqbgdemo_qt.po /templates/qt_widgets_cargo/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | src/ui_main.h 3 | -------------------------------------------------------------------------------- /logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KDE/rust-qt-binding-generator/HEAD/logo.png -------------------------------------------------------------------------------- /tests/rust_list/src/lib.rs: -------------------------------------------------------------------------------- 1 | extern crate libc; 2 | 3 | pub mod interface; 4 | mod implementation; 5 | -------------------------------------------------------------------------------- /tests/rust_object/src/lib.rs: -------------------------------------------------------------------------------- 1 | extern crate libc; 2 | 3 | pub mod interface; 4 | mod implementation; 5 | -------------------------------------------------------------------------------- /tests/rust_tree/src/lib.rs: -------------------------------------------------------------------------------- 1 | extern crate libc; 2 | 3 | pub mod interface; 4 | mod implementation; 5 | -------------------------------------------------------------------------------- /tutorial/demo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KDE/rust-qt-binding-generator/HEAD/tutorial/demo.png -------------------------------------------------------------------------------- /tutorial/demo2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KDE/rust-qt-binding-generator/HEAD/tutorial/demo2.png -------------------------------------------------------------------------------- /tutorial/demo3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KDE/rust-qt-binding-generator/HEAD/tutorial/demo3.png -------------------------------------------------------------------------------- /tutorial/time.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KDE/rust-qt-binding-generator/HEAD/tutorial/time.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | **/target/ 2 | **/*.rs.bk 3 | /docker_home/ 4 | 5 | # tutorial build 6 | /build/tutorial/ 7 | -------------------------------------------------------------------------------- /tests/rust_functions/src/lib.rs: -------------------------------------------------------------------------------- 1 | extern crate libc; 2 | 3 | pub mod interface; 4 | mod implementation; 5 | -------------------------------------------------------------------------------- /tests/rust_list_types/src/lib.rs: -------------------------------------------------------------------------------- 1 | extern crate libc; 2 | 3 | pub mod interface; 4 | mod implementation; 5 | -------------------------------------------------------------------------------- /tests/rust_objects/src/lib.rs: -------------------------------------------------------------------------------- 1 | extern crate libc; 2 | 3 | pub mod interface; 4 | mod implementation; 5 | -------------------------------------------------------------------------------- /examples/todos/rust/src/lib.rs: -------------------------------------------------------------------------------- 1 | 2 | extern crate libc; 3 | 4 | pub mod interface; 5 | mod implementation; 6 | -------------------------------------------------------------------------------- /examples/todos/todos.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KDE/rust-qt-binding-generator/HEAD/examples/todos/todos.png -------------------------------------------------------------------------------- /tests/rust_object_types/src/lib.rs: -------------------------------------------------------------------------------- 1 | extern crate libc; 2 | 3 | pub mod interface; 4 | mod implementation; 5 | -------------------------------------------------------------------------------- /tutorial/happy_time.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KDE/rust-qt-binding-generator/HEAD/tutorial/happy_time.png -------------------------------------------------------------------------------- /demo/screenshots/demo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KDE/rust-qt-binding-generator/HEAD/demo/screenshots/demo.png -------------------------------------------------------------------------------- /demo/screenshots/demo2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KDE/rust-qt-binding-generator/HEAD/demo/screenshots/demo2.png -------------------------------------------------------------------------------- /demo/screenshots/demo3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KDE/rust-qt-binding-generator/HEAD/demo/screenshots/demo3.png -------------------------------------------------------------------------------- /templates/qt_quick/rust/src/lib.rs: -------------------------------------------------------------------------------- 1 | 2 | extern crate libc; 3 | 4 | pub mod interface; 5 | mod implementation; 6 | -------------------------------------------------------------------------------- /templates/qt_widgets/rust/src/lib.rs: -------------------------------------------------------------------------------- 1 | 2 | extern crate libc; 3 | 4 | pub mod interface; 5 | mod implementation; 6 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Code: 2 | Jos van den Oever 3 | Art: 4 | Alessandro Longo 5 | -------------------------------------------------------------------------------- /examples/todos/qml.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | main.qml 4 | 5 | 6 | -------------------------------------------------------------------------------- /templates/qt_quick/qml.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | main.qml 4 | MainForm.ui.qml 5 | 6 | 7 | -------------------------------------------------------------------------------- /tutorial/SUMMARY.md: -------------------------------------------------------------------------------- 1 | # Summary 2 | 3 | [Rust Qt Binding Generator](./rust_qt_binding_generator.md) 4 | 5 | - [Rust and QML: a timely example](./time_for_rust_and_qml.md) 6 | -------------------------------------------------------------------------------- /templates/qt_quick_cargo/qml.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | main.qml 4 | MainForm.ui.qml 5 | 6 | 7 | -------------------------------------------------------------------------------- /examples/todos/rust/Cargo.toml: -------------------------------------------------------------------------------- 1 | 2 | [package] 3 | name = "rust" 4 | version = "1.0.0" 5 | 6 | [dependencies] 7 | libc = "*" 8 | 9 | [lib] 10 | name = "rust" 11 | crate-type = ["staticlib"] 12 | -------------------------------------------------------------------------------- /templates/qt_quick/rust/Cargo.toml: -------------------------------------------------------------------------------- 1 | 2 | [package] 3 | name = "rust" 4 | version = "1.0.0" 5 | 6 | [dependencies] 7 | libc = "0.2" 8 | 9 | [lib] 10 | name = "rust" 11 | crate-type = ["staticlib"] 12 | -------------------------------------------------------------------------------- /templates/qt_widgets/rust/Cargo.toml: -------------------------------------------------------------------------------- 1 | 2 | [package] 3 | name = "rust" 4 | version = "1.0.0" 5 | 6 | [dependencies] 7 | libc = "0.2" 8 | 9 | [lib] 10 | name = "rust" 11 | crate-type = ["staticlib"] 12 | -------------------------------------------------------------------------------- /tutorial/book.toml: -------------------------------------------------------------------------------- 1 | [book] 2 | title = "The official Rust Qt Binding Generator Guide" 3 | author = "Jos van den Oever" 4 | description = "Giving Rust a cute wrapping!" 5 | src = "." 6 | 7 | [build] 8 | build-dir = "../build/tutorial" 9 | -------------------------------------------------------------------------------- /tests/rust_list/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "rust_list" 3 | version = "1.0.0" 4 | 5 | [dependencies] 6 | libc = "0.2" 7 | 8 | [lib] 9 | name = "rust" 10 | crate-type = ["staticlib"] 11 | 12 | [profile.release] 13 | debug = true 14 | -------------------------------------------------------------------------------- /tests/rust_tree/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "rust_tree" 3 | version = "1.0.0" 4 | 5 | [dependencies] 6 | libc = "0.2" 7 | 8 | [lib] 9 | name = "rust" 10 | crate-type = ["staticlib"] 11 | 12 | [profile.release] 13 | debug = true 14 | -------------------------------------------------------------------------------- /tests/rust_object/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "rust_object" 3 | version = "1.0.0" 4 | 5 | [dependencies] 6 | libc = "0.2" 7 | 8 | [lib] 9 | name = "rust" 10 | crate-type = ["staticlib"] 11 | 12 | [profile.release] 13 | debug = true 14 | -------------------------------------------------------------------------------- /tests/rust_functions/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "rust_functions" 3 | version = "1.0.0" 4 | 5 | [dependencies] 6 | libc = "0.2" 7 | 8 | [lib] 9 | name = "rust" 10 | crate-type = ["staticlib"] 11 | 12 | [profile.release] 13 | debug = true 14 | -------------------------------------------------------------------------------- /tests/rust_list_types/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "rust_list" 3 | version = "1.0.0" 4 | 5 | [dependencies] 6 | libc = "0.2" 7 | 8 | [lib] 9 | name = "rust" 10 | crate-type = ["staticlib"] 11 | 12 | [profile.release] 13 | debug = true 14 | -------------------------------------------------------------------------------- /tests/rust_object_types/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "rust_object" 3 | version = "1.0.0" 4 | 5 | [dependencies] 6 | libc = "0.2" 7 | 8 | [lib] 9 | name = "rust" 10 | crate-type = ["staticlib"] 11 | 12 | [profile.release] 13 | debug = true 14 | -------------------------------------------------------------------------------- /tests/rust_objects/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "rust_objects" 3 | version = "1.0.0" 4 | 5 | [dependencies] 6 | libc = "0.2" 7 | 8 | [lib] 9 | name = "rust" 10 | crate-type = ["staticlib"] 11 | 12 | [profile.release] 13 | debug = true 14 | -------------------------------------------------------------------------------- /demo/rust/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "rust" 3 | version = "0.1.0" 4 | 5 | [dependencies] 6 | libc = "0.2" 7 | sysinfo = "0.4.1" 8 | 9 | [lib] 10 | name = "rust" 11 | crate-type = ["staticlib"] 12 | 13 | [profile.release] 14 | debug = true 15 | -------------------------------------------------------------------------------- /templates/qt_quick_cargo/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "qt_quick_cargo" 3 | version = "0.1.0" 4 | build = "build.rs" 5 | links = "qt_quick_cargo" 6 | 7 | [dependencies] 8 | libc = "0.2" 9 | 10 | [build-dependencies] 11 | rust_qt_binding_generator = { path = "../.." } 12 | -------------------------------------------------------------------------------- /templates/qt_widgets_cargo/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "qt_widgets_cargo" 3 | version = "0.1.0" 4 | build = "build.rs" 5 | links = "qt_widgets_cargo" 6 | 7 | [dependencies] 8 | libc = "0.2" 9 | 10 | [build-dependencies] 11 | rust_qt_binding_generator = { path = "../.." } 12 | -------------------------------------------------------------------------------- /demo/Messages.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Extract strings from all source files. 4 | # EXTRACT_TR_STRINGS extracts strings with lupdate and convert them to .pot with 5 | # lconvert. 6 | $EXTRACT_TR_STRINGS `find . -name \*.cpp -o -name \*.h -o -name \*.ui -o -name \*.qml` -o $podir/rqbgdemo_qt.pot 7 | -------------------------------------------------------------------------------- /examples/todos/cmake/FindRustQtBindingGenerator.cmake: -------------------------------------------------------------------------------- 1 | include(FindPackageHandleStandardArgs) 2 | find_program(RustQtBindingGenerator_EXECUTABLE rust_qt_binding_generator) 3 | find_package_handle_standard_args(RustQtBindingGenerator 4 | REQUIRED_VARS RustQtBindingGenerator_EXECUTABLE) 5 | mark_as_advanced(RustQtBindingGenerator_EXECUTABLE) 6 | -------------------------------------------------------------------------------- /templates/qt_quick/cmake/FindRustQtBindingGenerator.cmake: -------------------------------------------------------------------------------- 1 | include(FindPackageHandleStandardArgs) 2 | find_program(RustQtBindingGenerator_EXECUTABLE rust_qt_binding_generator) 3 | find_package_handle_standard_args(RustQtBindingGenerator 4 | REQUIRED_VARS RustQtBindingGenerator_EXECUTABLE) 5 | mark_as_advanced(RustQtBindingGenerator_EXECUTABLE) 6 | -------------------------------------------------------------------------------- /templates/qt_quick/README.md: -------------------------------------------------------------------------------- 1 | Qt Quick template project with Rust bindings 2 | 3 | This is a template project for writing a Qt Quick GUI on top of Rust code. 4 | 5 | bindings.json defines the interface between the Qt and Rust code. 6 | 7 | Build this code with 8 | 9 | ```bash 10 | mkdir build 11 | cd build 12 | cmake .. 13 | make 14 | ``` 15 | -------------------------------------------------------------------------------- /templates/qt_widgets/cmake/FindRustQtBindingGenerator.cmake: -------------------------------------------------------------------------------- 1 | include(FindPackageHandleStandardArgs) 2 | find_program(RustQtBindingGenerator_EXECUTABLE rust_qt_binding_generator) 3 | find_package_handle_standard_args(RustQtBindingGenerator 4 | REQUIRED_VARS RustQtBindingGenerator_EXECUTABLE) 5 | mark_as_advanced(RustQtBindingGenerator_EXECUTABLE) 6 | -------------------------------------------------------------------------------- /templates/qt_widgets/README.md: -------------------------------------------------------------------------------- 1 | Qt Widgets template project with Rust bindings 2 | 3 | This is a template project for writing a Qt Widgets GUI on top of Rust code. 4 | 5 | bindings.json defines the interface between the Qt and Rust code. 6 | 7 | Build this code with 8 | 9 | ```bash 10 | mkdir build 11 | cd build 12 | cmake .. 13 | make 14 | ``` 15 | -------------------------------------------------------------------------------- /templates/qt_quick_cargo/README.md: -------------------------------------------------------------------------------- 1 | Qt Quick template project with Rust bindings 2 | 3 | This is a template project for writing a Qt Quick GUI on top of Rust code. 4 | 5 | `bindings.json` defines the interface between the Qt and Rust code. 6 | 7 | Build instructions are written in `build.rs`. 8 | 9 | Build this code with 10 | 11 | ```bash 12 | cargo build 13 | ``` 14 | -------------------------------------------------------------------------------- /design.txt: -------------------------------------------------------------------------------- 1 | Communication between Rust and QML 2 | 3 | Access the Rust code as a QML type. 4 | 5 | 6 | Simple interface definition file generates a .h and .cpp files for QObject based classes. It also generates Rust files. It generates a trait that needs to be implemented and an empty definition for an implementation of that trait. The trait implementation needs to be filled in by the user. 7 | 8 | -------------------------------------------------------------------------------- /templates/qt_quick/main.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.6 2 | import QtQuick.Window 2.2 3 | 4 | Window { 5 | visible: true 6 | width: 640 7 | height: 480 8 | title: qsTr("Hello World") 9 | 10 | MainForm { 11 | anchors.fill: parent 12 | mouseArea.onClicked: { 13 | console.log(qsTr('Clicked on background. Text: "' + textEdit.text + '"')) 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /templates/qt_quick_cargo/main.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.6 2 | import QtQuick.Window 2.2 3 | 4 | Window { 5 | visible: true 6 | width: 640 7 | height: 480 8 | title: qsTr("Hello World") 9 | 10 | MainForm { 11 | anchors.fill: parent 12 | mouseArea.onClicked: { 13 | console.log(qsTr('Clicked on background. Text: "' + textEdit.text + '"')) 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /examples/todos/rust/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | [[package]] 4 | name = "libc" 5 | version = "0.2.92" 6 | source = "registry+https://github.com/rust-lang/crates.io-index" 7 | checksum = "56d855069fafbb9b344c0f962150cd2c1187975cb1c22c1522c240d8c4986714" 8 | 9 | [[package]] 10 | name = "rust" 11 | version = "1.0.0" 12 | dependencies = [ 13 | "libc", 14 | ] 15 | -------------------------------------------------------------------------------- /templates/qt_quick/rust/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | [[package]] 4 | name = "libc" 5 | version = "0.2.92" 6 | source = "registry+https://github.com/rust-lang/crates.io-index" 7 | checksum = "56d855069fafbb9b344c0f962150cd2c1187975cb1c22c1522c240d8c4986714" 8 | 9 | [[package]] 10 | name = "rust" 11 | version = "1.0.0" 12 | dependencies = [ 13 | "libc", 14 | ] 15 | -------------------------------------------------------------------------------- /tests/rust_list/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | [[package]] 4 | name = "libc" 5 | version = "0.2.92" 6 | source = "registry+https://github.com/rust-lang/crates.io-index" 7 | checksum = "56d855069fafbb9b344c0f962150cd2c1187975cb1c22c1522c240d8c4986714" 8 | 9 | [[package]] 10 | name = "rust_list" 11 | version = "1.0.0" 12 | dependencies = [ 13 | "libc", 14 | ] 15 | -------------------------------------------------------------------------------- /tests/rust_object/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | [[package]] 4 | name = "libc" 5 | version = "0.2.92" 6 | source = "registry+https://github.com/rust-lang/crates.io-index" 7 | checksum = "56d855069fafbb9b344c0f962150cd2c1187975cb1c22c1522c240d8c4986714" 8 | 9 | [[package]] 10 | name = "rust_object" 11 | version = "1.0.0" 12 | dependencies = [ 13 | "libc", 14 | ] 15 | -------------------------------------------------------------------------------- /tests/rust_tree/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | [[package]] 4 | name = "libc" 5 | version = "0.2.92" 6 | source = "registry+https://github.com/rust-lang/crates.io-index" 7 | checksum = "56d855069fafbb9b344c0f962150cd2c1187975cb1c22c1522c240d8c4986714" 8 | 9 | [[package]] 10 | name = "rust_tree" 11 | version = "1.0.0" 12 | dependencies = [ 13 | "libc", 14 | ] 15 | -------------------------------------------------------------------------------- /templates/qt_widgets/rust/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | [[package]] 4 | name = "libc" 5 | version = "0.2.92" 6 | source = "registry+https://github.com/rust-lang/crates.io-index" 7 | checksum = "56d855069fafbb9b344c0f962150cd2c1187975cb1c22c1522c240d8c4986714" 8 | 9 | [[package]] 10 | name = "rust" 11 | version = "1.0.0" 12 | dependencies = [ 13 | "libc", 14 | ] 15 | -------------------------------------------------------------------------------- /tests/rust_list_types/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | [[package]] 4 | name = "libc" 5 | version = "0.2.92" 6 | source = "registry+https://github.com/rust-lang/crates.io-index" 7 | checksum = "56d855069fafbb9b344c0f962150cd2c1187975cb1c22c1522c240d8c4986714" 8 | 9 | [[package]] 10 | name = "rust_list" 11 | version = "1.0.0" 12 | dependencies = [ 13 | "libc", 14 | ] 15 | -------------------------------------------------------------------------------- /tests/rust_objects/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | [[package]] 4 | name = "libc" 5 | version = "0.2.92" 6 | source = "registry+https://github.com/rust-lang/crates.io-index" 7 | checksum = "56d855069fafbb9b344c0f962150cd2c1187975cb1c22c1522c240d8c4986714" 8 | 9 | [[package]] 10 | name = "rust_objects" 11 | version = "1.0.0" 12 | dependencies = [ 13 | "libc", 14 | ] 15 | -------------------------------------------------------------------------------- /cmake/FindRust.cmake: -------------------------------------------------------------------------------- 1 | include(FindPackageHandleStandardArgs) 2 | find_program(Rust_EXECUTABLE rustc) 3 | execute_process(COMMAND "${Rust_EXECUTABLE}" --version 4 | OUTPUT_VARIABLE Rust_VERSION_OUTPUT) 5 | STRING(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" 6 | Rust_VERSION "${Rust_VERSION_OUTPUT}") 7 | find_package_handle_standard_args(Rust 8 | REQUIRED_VARS Rust_EXECUTABLE 9 | VERSION_VAR Rust_VERSION) 10 | mark_as_advanced(Rust_EXECUTABLE) 11 | -------------------------------------------------------------------------------- /tests/rust_functions/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | [[package]] 4 | name = "libc" 5 | version = "0.2.92" 6 | source = "registry+https://github.com/rust-lang/crates.io-index" 7 | checksum = "56d855069fafbb9b344c0f962150cd2c1187975cb1c22c1522c240d8c4986714" 8 | 9 | [[package]] 10 | name = "rust_functions" 11 | version = "1.0.0" 12 | dependencies = [ 13 | "libc", 14 | ] 15 | -------------------------------------------------------------------------------- /tests/rust_object_types/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | [[package]] 4 | name = "libc" 5 | version = "0.2.92" 6 | source = "registry+https://github.com/rust-lang/crates.io-index" 7 | checksum = "56d855069fafbb9b344c0f962150cd2c1187975cb1c22c1522c240d8c4986714" 8 | 9 | [[package]] 10 | name = "rust_object" 11 | version = "1.0.0" 12 | dependencies = [ 13 | "libc", 14 | ] 15 | -------------------------------------------------------------------------------- /COPYING.EXCEPTION: -------------------------------------------------------------------------------- 1 | LICENSE EXCEPTION 2 | 3 | In addition, as a special exception, the output, including source code, that 4 | this program generates, is not governed by this license. That is, anyone using 5 | this program is free to license its output, together with his or her program 6 | that the output is linked with, according to his or her own will. This is true, 7 | even though this program copies significant parts of its source code files to 8 | its output. 9 | -------------------------------------------------------------------------------- /shell.nix: -------------------------------------------------------------------------------- 1 | with import {}; 2 | 3 | stdenv.mkDerivation { 4 | name = "rust-env"; 5 | buildInputs = [ 6 | rustc 7 | cargo 8 | clippy 9 | rustfmt 10 | cmake ninja openssl pkgconfig 11 | extra-cmake-modules 12 | qt5.qtcharts 13 | qt5.qtquickcontrols 14 | qt5.qtquickcontrols2 15 | libsForQt5.kirigami2 16 | valgrind gdb 17 | ]; 18 | 19 | # Set Environment Variables 20 | RUST_BACKTRACE = 1; 21 | } 22 | -------------------------------------------------------------------------------- /examples/todos/cmake/FindRust.cmake: -------------------------------------------------------------------------------- 1 | include(FindPackageHandleStandardArgs) 2 | find_program(Rust_EXECUTABLE rustc) 3 | execute_process(COMMAND "${Rust_EXECUTABLE}" --version 4 | OUTPUT_VARIABLE Rust_VERSION_OUTPUT) 5 | STRING(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" 6 | Rust_VERSION "${Rust_VERSION_OUTPUT}") 7 | find_package_handle_standard_args(Rust 8 | REQUIRED_VARS Rust_EXECUTABLE 9 | VERSION_VAR Rust_VERSION) 10 | mark_as_advanced(Rust_EXECUTABLE) 11 | -------------------------------------------------------------------------------- /templates/qt_quick/cmake/FindRust.cmake: -------------------------------------------------------------------------------- 1 | include(FindPackageHandleStandardArgs) 2 | find_program(Rust_EXECUTABLE rustc) 3 | execute_process(COMMAND "${Rust_EXECUTABLE}" --version 4 | OUTPUT_VARIABLE Rust_VERSION_OUTPUT) 5 | STRING(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" 6 | Rust_VERSION "${Rust_VERSION_OUTPUT}") 7 | find_package_handle_standard_args(Rust 8 | REQUIRED_VARS Rust_EXECUTABLE 9 | VERSION_VAR Rust_VERSION) 10 | mark_as_advanced(Rust_EXECUTABLE) 11 | -------------------------------------------------------------------------------- /templates/qt_widgets_cargo/README.md: -------------------------------------------------------------------------------- 1 | Qt Widgets template project with Rust bindings 2 | 3 | This is a template project for writing a Qt Widgets GUI on top of Rust code. 4 | 5 | `bindings.json` defines the interface between the Qt and Rust code. 6 | 7 | `main.ui` is a Qt Designer interface specification that is used to generates UI code. 8 | 9 | Build instructions are written in `build.rs`. 10 | 11 | Build this code with 12 | 13 | ```bash 14 | cargo build 15 | ``` 16 | -------------------------------------------------------------------------------- /examples/todos/cmake/FindCargo.cmake: -------------------------------------------------------------------------------- 1 | include(FindPackageHandleStandardArgs) 2 | find_program(Cargo_EXECUTABLE cargo) 3 | execute_process(COMMAND "${Cargo_EXECUTABLE}" --version 4 | OUTPUT_VARIABLE Cargo_VERSION_OUTPUT) 5 | STRING(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" 6 | Cargo_VERSION "${Cargo_VERSION_OUTPUT}") 7 | find_package_handle_standard_args(Cargo 8 | REQUIRED_VARS Cargo_EXECUTABLE 9 | VERSION_VAR Cargo_VERSION) 10 | mark_as_advanced(Cargo_EXECUTABLE) 11 | -------------------------------------------------------------------------------- /templates/qt_widgets/cmake/FindRust.cmake: -------------------------------------------------------------------------------- 1 | include(FindPackageHandleStandardArgs) 2 | find_program(Rust_EXECUTABLE rustc) 3 | execute_process(COMMAND "${Rust_EXECUTABLE}" --version 4 | OUTPUT_VARIABLE Rust_VERSION_OUTPUT) 5 | STRING(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" 6 | Rust_VERSION "${Rust_VERSION_OUTPUT}") 7 | find_package_handle_standard_args(Rust 8 | REQUIRED_VARS Rust_EXECUTABLE 9 | VERSION_VAR Rust_VERSION) 10 | mark_as_advanced(Rust_EXECUTABLE) 11 | -------------------------------------------------------------------------------- /templates/qt_quick/cmake/FindCargo.cmake: -------------------------------------------------------------------------------- 1 | include(FindPackageHandleStandardArgs) 2 | find_program(Cargo_EXECUTABLE cargo) 3 | execute_process(COMMAND "${Cargo_EXECUTABLE}" --version 4 | OUTPUT_VARIABLE Cargo_VERSION_OUTPUT) 5 | STRING(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" 6 | Cargo_VERSION "${Cargo_VERSION_OUTPUT}") 7 | find_package_handle_standard_args(Cargo 8 | REQUIRED_VARS Cargo_EXECUTABLE 9 | VERSION_VAR Cargo_VERSION) 10 | mark_as_advanced(Cargo_EXECUTABLE) 11 | -------------------------------------------------------------------------------- /examples/todos/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include "Bindings.h" 2 | 3 | #include 4 | #include 5 | 6 | int main(int argc, char *argv[]) 7 | { 8 | QGuiApplication app(argc, argv); 9 | qmlRegisterType("RustCode", 1, 0, "Todos"); 10 | 11 | QQmlApplicationEngine engine; 12 | engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); 13 | if (engine.rootObjects().isEmpty()) 14 | return -1; 15 | 16 | return app.exec(); 17 | } 18 | -------------------------------------------------------------------------------- /templates/qt_widgets/cmake/FindCargo.cmake: -------------------------------------------------------------------------------- 1 | include(FindPackageHandleStandardArgs) 2 | find_program(Cargo_EXECUTABLE cargo) 3 | execute_process(COMMAND "${Cargo_EXECUTABLE}" --version 4 | OUTPUT_VARIABLE Cargo_VERSION_OUTPUT) 5 | STRING(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" 6 | Cargo_VERSION "${Cargo_VERSION_OUTPUT}") 7 | find_package_handle_standard_args(Cargo 8 | REQUIRED_VARS Cargo_EXECUTABLE 9 | VERSION_VAR Cargo_VERSION) 10 | mark_as_advanced(Cargo_EXECUTABLE) 11 | -------------------------------------------------------------------------------- /templates/qt_quick_cargo/build.rs: -------------------------------------------------------------------------------- 1 | extern crate rust_qt_binding_generator; 2 | 3 | use rust_qt_binding_generator::build::QtModule; 4 | 5 | fn main() { 6 | let out_dir = ::std::env::var("OUT_DIR").unwrap(); 7 | rust_qt_binding_generator::build::Build::new(&out_dir) 8 | .bindings("bindings.json") 9 | .qrc("qml.qrc") 10 | .cpp("src/main.cpp") 11 | .module(QtModule::Gui) 12 | .module(QtModule::Qml) 13 | .compile("qt_quick_cargo"); 14 | } 15 | -------------------------------------------------------------------------------- /templates/qt_widgets/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include "Bindings.h" 2 | #include 3 | #include 4 | 5 | int main(int argc, char* argv[]) 6 | { 7 | QApplication app(argc, argv); 8 | Simple simple; // This is the Rust object 9 | QMessageBox msgBox; 10 | msgBox.setText(simple.message()); 11 | msgBox.connect(&msgBox, &QMessageBox::finished, &msgBox, []() { 12 | QCoreApplication::quit(); 13 | }); 14 | msgBox.show(); 15 | 16 | return app.exec(); 17 | } 18 | -------------------------------------------------------------------------------- /templates/qt_widgets_cargo/build.rs: -------------------------------------------------------------------------------- 1 | extern crate rust_qt_binding_generator; 2 | 3 | use rust_qt_binding_generator::build::QtModule; 4 | 5 | fn main() { 6 | let out_dir = ::std::env::var("OUT_DIR").unwrap(); 7 | rust_qt_binding_generator::build::Build::new(&out_dir) 8 | .bindings("bindings.json") 9 | .ui("src/main.ui") 10 | .cpp("src/main.cpp") 11 | .module(QtModule::Gui) 12 | .module(QtModule::Widgets) 13 | .compile("qt_widgets_cargo"); 14 | } 15 | -------------------------------------------------------------------------------- /templates/qt_quick_cargo/src/main.rs: -------------------------------------------------------------------------------- 1 | extern crate libc; 2 | 3 | mod implementation; 4 | pub mod interface { 5 | include!(concat!(env!("OUT_DIR"), "/src/interface.rs")); 6 | } 7 | 8 | extern { 9 | fn main_cpp(app: *const ::std::os::raw::c_char); 10 | } 11 | 12 | fn main() { 13 | use std::ffi::CString; 14 | let app_name = ::std::env::args().next().unwrap(); 15 | let app_name = CString::new(app_name).unwrap(); 16 | unsafe { 17 | main_cpp(app_name.as_ptr()); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /templates/qt_widgets_cargo/src/main.rs: -------------------------------------------------------------------------------- 1 | extern crate libc; 2 | 3 | mod implementation; 4 | pub mod interface { 5 | include!(concat!(env!("OUT_DIR"), "/src/interface.rs")); 6 | } 7 | 8 | extern "C" { 9 | fn main_cpp(app: *const ::std::os::raw::c_char); 10 | } 11 | 12 | fn main() { 13 | use std::ffi::CString; 14 | let app_name = ::std::env::args().next().unwrap(); 15 | let app_name = CString::new(app_name).unwrap(); 16 | unsafe { 17 | main_cpp(app_name.as_ptr()); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /templates/qt_quick/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include "Bindings.h" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | int main(int argc, char *argv[]) 8 | { 9 | QGuiApplication app(argc, argv); 10 | qmlRegisterType("RustCode", 1, 0, "Simple"); 11 | 12 | QQmlApplicationEngine engine; 13 | engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); 14 | if (engine.rootObjects().isEmpty()) 15 | return -1; 16 | 17 | return app.exec(); 18 | } 19 | -------------------------------------------------------------------------------- /templates/qt_quick_cargo/bindings.json: -------------------------------------------------------------------------------- 1 | { 2 | "cppFile": "Bindings.cpp", 3 | "rust": { 4 | "dir": "", 5 | "interfaceModule": "interface", 6 | "implementationModule": "implementation" 7 | }, 8 | "objects": { 9 | "Simple": { 10 | "type": "Object", 11 | "properties": { 12 | "message": { 13 | "type": "QString", 14 | "write": true 15 | } 16 | } 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /templates/qt_quick/bindings.json: -------------------------------------------------------------------------------- 1 | { 2 | "cppFile": "src/Bindings.cpp", 3 | "rust": { 4 | "dir": "rust", 5 | "interfaceModule": "interface", 6 | "implementationModule": "implementation" 7 | }, 8 | "objects": { 9 | "Simple": { 10 | "type": "Object", 11 | "properties": { 12 | "message": { 13 | "type": "QString", 14 | "write": true 15 | } 16 | } 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /templates/qt_widgets/bindings.json: -------------------------------------------------------------------------------- 1 | { 2 | "cppFile": "src/Bindings.cpp", 3 | "rust": { 4 | "dir": "rust", 5 | "interfaceModule": "interface", 6 | "implementationModule": "implementation" 7 | }, 8 | "objects": { 9 | "Simple": { 10 | "type": "Object", 11 | "properties": { 12 | "message": { 13 | "type": "QString", 14 | "write": true 15 | } 16 | } 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /templates/qt_widgets_cargo/bindings.json: -------------------------------------------------------------------------------- 1 | { 2 | "cppFile": "Bindings.cpp", 3 | "rust": { 4 | "dir": "", 5 | "interfaceModule": "interface", 6 | "implementationModule": "implementation" 7 | }, 8 | "objects": { 9 | "Simple": { 10 | "type": "Object", 11 | "properties": { 12 | "message": { 13 | "type": "QString", 14 | "write": true 15 | } 16 | } 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /tests/test_object.json: -------------------------------------------------------------------------------- 1 | { 2 | "cppFile": "test_object_rust.cpp", 3 | "rust": { 4 | "dir": "rust_object", 5 | "interfaceModule": "interface", 6 | "implementationModule": "implementation" 7 | }, 8 | "objects": { 9 | "Person": { 10 | "type": "Object", 11 | "properties": { 12 | "userName": { 13 | "type": "QString", 14 | "write": true 15 | } 16 | } 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /examples/todos/README.md: -------------------------------------------------------------------------------- 1 | ![Todos application](todos.png) 2 | 3 | Source code for https://fosdem.org/2018/schedule/event/rust_qt_binding_generator/ 4 | 5 | This is an implementation of the [TodoMVC specification](https://github.com/tastejs/todomvc/blob/master/app-spec.md). 6 | 7 | Make sure `rust_qt_binding_generator` is in the `PATH`. 8 | 9 | ```bash 10 | mkdir build 11 | cd build 12 | cmake -GNinja .. 13 | ninja 14 | export QT_QUICK_CONTROLS_MATERIAL_THEME=Dark 15 | export QT_QUICK_CONTROLS_STYLE=Material 16 | ./todos 17 | ``` 18 | -------------------------------------------------------------------------------- /src/README.md: -------------------------------------------------------------------------------- 1 | # Bindings between Qt and Rust 2 | 3 | ## Glossary 4 | 5 | ### Property type 6 | 7 | The type that is written in the JSON file. This is the type that is type that 8 | is used in the C++ code. 9 | 10 | ### binding type 11 | 12 | The type that is used to transer the data between the Rust and Qt. 13 | 14 | ### C++ binding type 15 | 16 | The C++ version of the type that is transferred between Rust and Qt. 17 | 18 | ### Rust binding type 19 | 20 | The Rust version of the type that is transferred between Rust and Qt. 21 | 22 | -------------------------------------------------------------------------------- /tests/test_tree.json: -------------------------------------------------------------------------------- 1 | { 2 | "cppFile": "test_tree_rust.cpp", 3 | "rust": { 4 | "dir": "rust_tree", 5 | "interfaceModule": "interface", 6 | "implementationModule": "implementation" 7 | }, 8 | "objects": { 9 | "Persons": { 10 | "type": "Tree", 11 | "itemProperties": { 12 | "userName": { 13 | "type": "QString", 14 | "write": true, 15 | "roles": [ [ "display", "edit" ] ] 16 | } 17 | } 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/util.rs: -------------------------------------------------------------------------------- 1 | use regex::Regex; 2 | use std::fs; 3 | use std::io::Result; 4 | use std::path::Path; 5 | 6 | pub fn write_if_different>(path: P, contents: &[u8]) -> Result<()> { 7 | let old_contents = fs::read(&path).ok(); 8 | if old_contents.map(|c| c == contents).unwrap_or(false) { 9 | Ok(()) 10 | } else { 11 | let _ = fs::create_dir_all(path.as_ref().parent().unwrap()); 12 | fs::write(path, contents) 13 | } 14 | } 15 | 16 | pub fn snake_case(name: &str) -> String { 17 | let re = Regex::new("([A-Z])").unwrap(); 18 | (name[..1].to_string() + &re.replace_all(&name[1..], "_$1")).to_lowercase() 19 | } 20 | -------------------------------------------------------------------------------- /templates/qt_quick/rust/src/implementation.rs: -------------------------------------------------------------------------------- 1 | use interface::*; 2 | 3 | pub struct Simple { 4 | emit: SimpleEmitter, 5 | message: String, 6 | } 7 | 8 | impl SimpleTrait for Simple { 9 | fn new(emit: SimpleEmitter) -> Simple { 10 | Simple { 11 | emit: emit, 12 | message: String::new(), 13 | } 14 | } 15 | fn emit(&mut self) -> &mut SimpleEmitter { 16 | &mut self.emit 17 | } 18 | fn message(&self) -> &str { 19 | "Hello World!" 20 | } 21 | fn set_message(&mut self, value: String) { 22 | self.message = value; 23 | self.emit.message_changed(); 24 | } 25 | } 26 | 27 | -------------------------------------------------------------------------------- /templates/qt_quick_cargo/src/implementation.rs: -------------------------------------------------------------------------------- 1 | use interface::*; 2 | 3 | pub struct Simple { 4 | emit: SimpleEmitter, 5 | message: String, 6 | } 7 | 8 | impl SimpleTrait for Simple { 9 | fn new(emit: SimpleEmitter) -> Simple { 10 | Simple { 11 | emit: emit, 12 | message: String::new(), 13 | } 14 | } 15 | fn emit(&mut self) -> &mut SimpleEmitter { 16 | &mut self.emit 17 | } 18 | fn message(&self) -> &str { 19 | "Hello World!" 20 | } 21 | fn set_message(&mut self, value: String) { 22 | self.message = value; 23 | self.emit.message_changed(); 24 | } 25 | } 26 | 27 | -------------------------------------------------------------------------------- /templates/qt_widgets/rust/src/implementation.rs: -------------------------------------------------------------------------------- 1 | use interface::*; 2 | 3 | pub struct Simple { 4 | emit: SimpleEmitter, 5 | message: String, 6 | } 7 | 8 | impl SimpleTrait for Simple { 9 | fn new(emit: SimpleEmitter) -> Simple { 10 | Simple { 11 | emit: emit, 12 | message: String::new(), 13 | } 14 | } 15 | fn emit(&mut self) -> &mut SimpleEmitter { 16 | &mut self.emit 17 | } 18 | fn message(&self) -> &str { 19 | "Hello World!" 20 | } 21 | fn set_message(&mut self, value: String) { 22 | self.message = value; 23 | self.emit.message_changed(); 24 | } 25 | } 26 | 27 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "rust_qt_binding_generator" 3 | version = "0.3.6" 4 | authors = ["Jos van den Oever "] 5 | description = "Generate code to build Qt applications with Rust" 6 | license = "AGPL-3.0-or-later" 7 | documentation = "https://phabricator.kde.org/source/rust-qt-binding-generator/" 8 | homepage = "https://phabricator.kde.org/source/rust-qt-binding-generator/" 9 | repository = "https://anongit.kde.org/rust-qt-binding-generator" 10 | 11 | [dependencies] 12 | cc = { version = "1", features = ["parallel"] } 13 | clap = "2" 14 | regex= "1" 15 | serde = "1.0" 16 | serde-xml-rs = "0.4" 17 | serde_derive = "1.0" 18 | serde_json = "1.0" 19 | toml = "0.5" 20 | -------------------------------------------------------------------------------- /templates/qt_widgets_cargo/src/implementation.rs: -------------------------------------------------------------------------------- 1 | use interface::*; 2 | 3 | pub struct Simple { 4 | emit: SimpleEmitter, 5 | message: String, 6 | } 7 | 8 | impl SimpleTrait for Simple { 9 | fn new(emit: SimpleEmitter) -> Simple { 10 | Simple { 11 | emit: emit, 12 | message: String::new(), 13 | } 14 | } 15 | fn emit(&mut self) -> &mut SimpleEmitter { 16 | &mut self.emit 17 | } 18 | fn message(&self) -> &str { 19 | self.message.as_str() 20 | } 21 | fn set_message(&mut self, value: String) { 22 | if self.message != value { 23 | self.message = value; 24 | self.emit.message_changed(); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /tests/rust_object/src/implementation.rs: -------------------------------------------------------------------------------- 1 | #![allow(unused_imports)] 2 | #![allow(unused_variables)] 3 | #![allow(dead_code)] 4 | use interface::*; 5 | 6 | pub struct Person { 7 | emit: PersonEmitter, 8 | user_name: String, 9 | } 10 | 11 | impl PersonTrait for Person { 12 | fn new(emit: PersonEmitter) -> Person { 13 | Person { 14 | emit: emit, 15 | user_name: String::new(), 16 | } 17 | } 18 | fn emit(&mut self) -> &mut PersonEmitter { 19 | &mut self.emit 20 | } 21 | fn user_name(&self) -> &str { 22 | &self.user_name 23 | } 24 | fn set_user_name(&mut self, value: String) { 25 | self.user_name = value; 26 | self.emit.user_name_changed(); 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /templates/qt_quick/src/Bindings.h: -------------------------------------------------------------------------------- 1 | /* generated by rust_qt_binding_generator */ 2 | #ifndef BINDINGS_H 3 | #define BINDINGS_H 4 | 5 | #include 6 | #include 7 | 8 | class Simple; 9 | 10 | class Simple : public QObject 11 | { 12 | Q_OBJECT 13 | public: 14 | class Private; 15 | private: 16 | Private * m_d; 17 | bool m_ownsPrivate; 18 | Q_PROPERTY(QString message READ message WRITE setMessage NOTIFY messageChanged FINAL) 19 | explicit Simple(bool owned, QObject *parent); 20 | public: 21 | explicit Simple(QObject *parent = nullptr); 22 | ~Simple(); 23 | QString message() const; 24 | void setMessage(const QString& v); 25 | Q_SIGNALS: 26 | void messageChanged(); 27 | }; 28 | #endif // BINDINGS_H 29 | -------------------------------------------------------------------------------- /templates/qt_widgets/src/Bindings.h: -------------------------------------------------------------------------------- 1 | /* generated by rust_qt_binding_generator */ 2 | #ifndef BINDINGS_H 3 | #define BINDINGS_H 4 | 5 | #include 6 | #include 7 | 8 | class Simple; 9 | 10 | class Simple : public QObject 11 | { 12 | Q_OBJECT 13 | public: 14 | class Private; 15 | private: 16 | Private * m_d; 17 | bool m_ownsPrivate; 18 | Q_PROPERTY(QString message READ message WRITE setMessage NOTIFY messageChanged FINAL) 19 | explicit Simple(bool owned, QObject *parent); 20 | public: 21 | explicit Simple(QObject *parent = nullptr); 22 | ~Simple(); 23 | QString message() const; 24 | void setMessage(const QString& v); 25 | Q_SIGNALS: 26 | void messageChanged(); 27 | }; 28 | #endif // BINDINGS_H 29 | -------------------------------------------------------------------------------- /tests/test_object_rust.h: -------------------------------------------------------------------------------- 1 | /* generated by rust_qt_binding_generator */ 2 | #ifndef TEST_OBJECT_RUST_H 3 | #define TEST_OBJECT_RUST_H 4 | 5 | #include 6 | #include 7 | 8 | class Person; 9 | 10 | class Person : public QObject 11 | { 12 | Q_OBJECT 13 | public: 14 | class Private; 15 | private: 16 | Private * m_d; 17 | bool m_ownsPrivate; 18 | Q_PROPERTY(QString userName READ userName WRITE setUserName NOTIFY userNameChanged FINAL) 19 | explicit Person(bool owned, QObject *parent); 20 | public: 21 | explicit Person(QObject *parent = nullptr); 22 | ~Person(); 23 | QString userName() const; 24 | void setUserName(const QString& v); 25 | Q_SIGNALS: 26 | void userNameChanged(); 27 | }; 28 | #endif // TEST_OBJECT_RUST_H 29 | -------------------------------------------------------------------------------- /templates/qt_quick_cargo/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include "Bindings.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | extern "C" { 9 | int main_cpp(const char* app); 10 | } 11 | 12 | int main_cpp(const char* appPath) 13 | { 14 | int argc = 1; 15 | char* argv[1] = { (char*)appPath }; 16 | QGuiApplication app(argc, argv); 17 | qmlRegisterType("RustCode", 1, 0, "Simple"); 18 | 19 | QQmlApplicationEngine engine; 20 | if (QFile("main.qml").exists()) { 21 | engine.load(QUrl(QStringLiteral("main.qml"))); 22 | } else { 23 | engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); 24 | } 25 | if (engine.rootObjects().isEmpty()) 26 | return -1; 27 | 28 | return app.exec(); 29 | } 30 | -------------------------------------------------------------------------------- /templates/qt_quick/MainForm.ui.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.6 2 | import RustCode 1.0 3 | 4 | Rectangle { 5 | property alias mouseArea: mouseArea 6 | property alias textEdit: textEdit 7 | 8 | Simple { 9 | id: rust 10 | } 11 | 12 | width: 360 13 | height: 360 14 | 15 | MouseArea { 16 | id: mouseArea 17 | anchors.fill: parent 18 | } 19 | 20 | TextEdit { 21 | id: textEdit 22 | text: rust.message 23 | verticalAlignment: Text.AlignVCenter 24 | anchors.top: parent.top 25 | anchors.horizontalCenter: parent.horizontalCenter 26 | anchors.topMargin: 20 27 | Rectangle { 28 | anchors.fill: parent 29 | anchors.margins: -10 30 | color: "transparent" 31 | border.width: 1 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /templates/qt_quick_cargo/MainForm.ui.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.6 2 | import RustCode 1.0 3 | 4 | Rectangle { 5 | property alias mouseArea: mouseArea 6 | property alias textEdit: textEdit 7 | 8 | Simple { 9 | id: rust 10 | } 11 | 12 | width: 360 13 | height: 360 14 | 15 | MouseArea { 16 | id: mouseArea 17 | anchors.fill: parent 18 | } 19 | 20 | TextEdit { 21 | id: textEdit 22 | text: rust.message 23 | verticalAlignment: Text.AlignVCenter 24 | anchors.top: parent.top 25 | anchors.horizontalCenter: parent.horizontalCenter 26 | anchors.topMargin: 20 27 | Rectangle { 28 | anchors.fill: parent 29 | anchors.margins: -10 30 | color: "transparent" 31 | border.width: 1 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /demo/resource_file.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | rust_qt_binding_generator.svg 4 | qml/DataAndChart.qml 5 | qml/Fibonacci.qml 6 | qml/Fibonacci2.qml 7 | qml/FibonacciList.qml 8 | qml/FibonacciList2.qml 9 | qml/FileTreeView.qml 10 | qml/FileTreeView2.qml 11 | qml/ProcessesTree.qml 12 | qml/StyleSwitcher.qml 13 | qml/StyleSwitcher2.qml 14 | qml/chart.qml 15 | qml/demo-qtquick2.qml 16 | qml/demo.qml 17 | qml/demo-kirigami2.qml 18 | qml/FibonacciListKirigami.qml 19 | qml/FileTreeViewKirigami.qml 20 | 21 | 22 | -------------------------------------------------------------------------------- /tests/test_list.json: -------------------------------------------------------------------------------- 1 | { 2 | "cppFile": "test_list_rust.cpp", 3 | "rust": { 4 | "dir": "rust_list", 5 | "interfaceModule": "interface", 6 | "implementationModule": "implementation" 7 | }, 8 | "objects": { 9 | "Persons": { 10 | "type": "List", 11 | "itemProperties": { 12 | "userName": { 13 | "type": "QString", 14 | "write": true, 15 | "roles": [ [ "display", "edit" ] ] 16 | } 17 | } 18 | }, 19 | "NoRole": { 20 | "type": "List", 21 | "itemProperties": { 22 | "userName": { 23 | "type": "QString", 24 | "write": true 25 | }, 26 | "userAge": { 27 | "type": "quint8", 28 | "write": true 29 | } 30 | } 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /tests/test_objects.json: -------------------------------------------------------------------------------- 1 | { 2 | "cppFile": "test_objects_rust.cpp", 3 | "rust": { 4 | "dir": "rust_objects", 5 | "interfaceModule": "interface", 6 | "implementationModule": "implementation" 7 | }, 8 | "objects": { 9 | "InnerObject": { 10 | "type": "Object", 11 | "properties": { 12 | "description": { 13 | "type": "QString", 14 | "write": true 15 | } 16 | } 17 | }, 18 | "Person": { 19 | "type": "Object", 20 | "properties": { 21 | "object": { 22 | "type": "InnerObject" 23 | } 24 | } 25 | }, 26 | "Group": { 27 | "type": "Object", 28 | "properties": { 29 | "person": { 30 | "type": "Person" 31 | } 32 | } 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /demo/rust/src/lib.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Jos van den Oever 2 | // 3 | // This program is free software; you can redistribute it and/or 4 | // modify it under the terms of the GNU General Public License as 5 | // published by the Free Software Foundation; either version 2 of 6 | // the License or (at your option) version 3 or any later version 7 | // accepted by the membership of KDE e.V. (or its successor approved 8 | // by the membership of KDE e.V.), which shall act as a proxy 9 | // defined in Section 14 of version 3 of the license. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | extern crate libc; 20 | extern crate sysinfo; 21 | 22 | mod implementation; 23 | pub mod interface; 24 | -------------------------------------------------------------------------------- /src/bin/rust_qt_binding_generator.rs: -------------------------------------------------------------------------------- 1 | extern crate clap; 2 | extern crate rust_qt_binding_generator; 3 | use clap::{App, Arg}; 4 | use rust_qt_binding_generator::*; 5 | 6 | fn main() { 7 | let matches = App::new("rust_qt_binding_generator") 8 | .version(env!("CARGO_PKG_VERSION")) 9 | .about("Generates bindings between Qt and Rust") 10 | .arg( 11 | Arg::with_name("overwrite-implementation") 12 | .long("overwrite-implementation") 13 | .help("Overwrite existing implementation."), 14 | ) 15 | .arg( 16 | Arg::with_name("config") 17 | .multiple(true) 18 | .required(true) 19 | .takes_value(true) 20 | .help("Configuration file(s)"), 21 | ) 22 | .get_matches(); 23 | 24 | let overwrite_implementation = matches.is_present("overwrite-implementation"); 25 | for config in matches.values_of("config").unwrap() { 26 | if let Err(e) = generate_bindings_from_config_file(config, overwrite_implementation) { 27 | eprintln!("{}", e); 28 | ::std::process::exit(1); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /tests/test_functions_rust.h: -------------------------------------------------------------------------------- 1 | /* generated by rust_qt_binding_generator */ 2 | #ifndef TEST_FUNCTIONS_RUST_H 3 | #define TEST_FUNCTIONS_RUST_H 4 | 5 | #include 6 | #include 7 | 8 | class Person; 9 | 10 | class Person : public QObject 11 | { 12 | Q_OBJECT 13 | public: 14 | class Private; 15 | private: 16 | Private * m_d; 17 | bool m_ownsPrivate; 18 | Q_PROPERTY(QString userName READ userName WRITE setUserName NOTIFY userNameChanged FINAL) 19 | explicit Person(bool owned, QObject *parent); 20 | public: 21 | explicit Person(QObject *parent = nullptr); 22 | ~Person(); 23 | QString userName() const; 24 | void setUserName(const QString& v); 25 | Q_INVOKABLE void append(const QString& suffix, quint32 amount); 26 | Q_INVOKABLE void doubleName(); 27 | Q_INVOKABLE QString greet(const QString& name) const; 28 | Q_INVOKABLE QString quote(const QString& prefix, const QString& suffix) const; 29 | Q_INVOKABLE QByteArray quoteBytes(const QByteArray& prefix, const QByteArray& suffix) const; 30 | Q_INVOKABLE quint8 vowelsInName() const; 31 | Q_SIGNALS: 32 | void userNameChanged(); 33 | }; 34 | #endif // TEST_FUNCTIONS_RUST_H 35 | -------------------------------------------------------------------------------- /demo/rust/src/implementation/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Jos van den Oever 2 | // 3 | // This program is free software; you can redistribute it and/or 4 | // modify it under the terms of the GNU General Public License as 5 | // published by the Free Software Foundation; either version 2 of 6 | // the License or (at your option) version 3 or any later version 7 | // accepted by the membership of KDE e.V. (or its successor approved 8 | // by the membership of KDE e.V.), which shall act as a proxy 9 | // defined in Section 14 of version 3 of the license. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | mod demo; 20 | mod fibonacci; 21 | mod file_system_tree; 22 | mod processes; 23 | mod time_series; 24 | 25 | pub use self::demo::*; 26 | pub use self::fibonacci::*; 27 | pub use self::file_system_tree::*; 28 | pub use self::processes::*; 29 | pub use self::time_series::*; 30 | -------------------------------------------------------------------------------- /docker/docker-bash-session.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # exit on first error 4 | set -o errexit 5 | # exit when undefined var is used 6 | set -o nounset 7 | # exit with error code of right-most command in a pipe 8 | set -o pipefail 9 | 10 | # This script opens a bash session in docker for the Dockerfile in this folder. 11 | 12 | readonly image_name=rust_qt_binding_generator_dev 13 | readonly docker_file_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 14 | readonly src_dir=$(dirname "$docker_file_dir") 15 | readonly docker_home_dir="$src_dir/docker_home" 16 | 17 | # create the docker image 18 | docker build -t "$image_name" "$docker_file_dir" 19 | 20 | # create a working directory 21 | if [ ! -a "$docker_home_dir" ]; then 22 | mkdir -p "$docker_home_dir"/rust_qt_binding_generator 23 | fi 24 | 25 | # give the docker application access to X 26 | xhost +si:localuser:"$USER" 27 | 28 | # start a docker session with the source code and a dedicated home directory 29 | docker run --rm -v "$docker_home_dir":/home/neon \ 30 | -v "$src_dir":/home/neon/rust_qt_binding_generator \ 31 | -v /tmp/.X11-unix:/tmp/.X11-unix \ 32 | -e DISPLAY="$DISPLAY" \ 33 | -e XDG_CURRENT_DESKTOP="$XDG_CURRENT_DESKTOP" \ 34 | -ti "$image_name" bash 35 | 36 | # --network none \ 37 | -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | extern crate regex; 2 | #[macro_use] 3 | extern crate serde_derive; 4 | extern crate serde_json; 5 | extern crate serde_xml_rs; 6 | extern crate toml; 7 | 8 | pub mod build; 9 | pub mod configuration; 10 | mod configuration_private; 11 | mod cpp; 12 | mod rust; 13 | mod util; 14 | 15 | use configuration::Config; 16 | use std::error::Error; 17 | use std::path::Path; 18 | 19 | /// Read a file with bindings. 20 | pub fn read_bindings_file>(config_file: P) -> Result> { 21 | configuration::parse(config_file) 22 | } 23 | 24 | /// Generate bindings from a bindings configuration. 25 | pub fn generate_bindings(config: &Config) -> Result<(), Box> { 26 | cpp::write_header(config)?; 27 | cpp::write_cpp(config)?; 28 | rust::write_interface(config)?; 29 | rust::write_implementation(config)?; 30 | Ok(()) 31 | } 32 | 33 | /// Generate bindings from a bindings configuration file. 34 | pub fn generate_bindings_from_config_file>( 35 | config_file: P, 36 | overwrite_implementation: bool, 37 | ) -> Result<(), Box> { 38 | let mut config = read_bindings_file(config_file)?; 39 | if overwrite_implementation { 40 | config.overwrite_implementation = true; 41 | } 42 | generate_bindings(&config) 43 | } 44 | -------------------------------------------------------------------------------- /ChangeLog: -------------------------------------------------------------------------------- 1 | 0.3.6 (2021-04-04) 2 | - Add "extern" keyword to extern functions to make them FFI-safe. 3 | 0.3.5 (2020-01-12) 4 | - Add project template with .ui file. 5 | - Update dependencies. 6 | - Omit parentheses from generated 'as (*const c_char) statements. 7 | - Do not warn about unused units. 8 | - Fix undefined reference when linking with Cargo. 9 | - Bugfix: write .into() for Option<> return types. 10 | 0.3.4 (2019-02-25) 11 | - Allow explicit adding of include directories and libraries to link 12 | 0.3.3 (2019-02-24) 13 | - Make it possible to specify C++ header files via mod build 14 | 0.3.2 (2019-02-13) 15 | - Add placeholder for variable name in generated code. 16 | 0.3.1 (2019-02-08) 17 | - Fix bug where Cargo.toml could not be found. 18 | 0.3.0 (2019-01-21) 19 | - Add function to Build to choose Qt modules to link to 20 | 0.2.2 (2018-12-10) 21 | - Fix build with rust <= 1.30 22 | 0.2.1 (2018-12-10) 23 | - Fix generated code for use with Rust edition 2018 (Owen Nelson, bug 401913) 24 | - Fix building with MSVC (bug 400716) 25 | 0.2.0 (2018-10-29) 26 | - Fix building with Cargo on Windows with MSVC (bug 400393) 27 | - Change generated API to avoid concurrent mutable and immutable references 28 | via callbacks into C++ 29 | 0.1.0 (2018-10-10) 30 | - Port to Rust 31 | - Publish as crate 32 | - Add tools to build 33 | -------------------------------------------------------------------------------- /templates/qt_widgets_cargo/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include "Bindings.h" 2 | 3 | #include "ui_main.h" 4 | 5 | extern "C" { 6 | int main_cpp(const char* app); 7 | } 8 | 9 | int main_cpp(const char* appPath) 10 | { 11 | int argc = 1; 12 | char* argv[1] = { (char*)appPath }; 13 | QApplication app(argc, argv); 14 | 15 | Simple simple; // This is the Rust object 16 | 17 | QMainWindow main; 18 | Ui_MainWindow ui; 19 | ui.setupUi(&main); 20 | 21 | // Quit the application by... 22 | // * Using the mouse to select File->Quit 23 | // * Pressing +F, +Q 24 | // * Pressing +Q 25 | QObject::connect(ui.action_Quit, &QAction::triggered, &app, &QApplication::closeAllWindows); 26 | 27 | // Update the status message whenever the rust message changes 28 | simple.connect(&simple, &Simple::messageChanged, ui.statusbar, [&simple, &ui]() { 29 | ui.statusbar->showMessage(simple.message()); 30 | }); 31 | 32 | // Update the rust message when the button is clicked 33 | ui.statusButton->connect(ui.statusButton, &QPushButton::clicked, &simple, [&simple, &ui]() { 34 | simple.setMessage(ui.statusEdit->text()); 35 | }); 36 | 37 | // Initialize gui/model state 38 | ui.statusEdit->setText("Hello World!"); 39 | ui.statusButton->clicked(); 40 | 41 | main.show(); 42 | 43 | return app.exec(); 44 | } 45 | -------------------------------------------------------------------------------- /src/configuration_private.rs: -------------------------------------------------------------------------------- 1 | use std::collections::BTreeSet; 2 | 3 | pub trait ConfigPrivate { 4 | fn types(&self) -> BTreeSet; 5 | fn optional_types(&self) -> BTreeSet; 6 | fn has_list_or_tree(&self) -> bool; 7 | } 8 | 9 | pub trait ObjectPrivate { 10 | fn contains_object(&self) -> bool; 11 | fn column_count(&self) -> usize; 12 | } 13 | 14 | pub trait TypeName { 15 | fn type_name(&self) -> &str; 16 | } 17 | 18 | pub trait TypePrivate { 19 | fn is_object(&self) -> bool; 20 | fn is_complex(&self) -> bool; 21 | fn name(&self) -> &str; 22 | fn cpp_set_type(&self) -> &str; 23 | fn c_set_type(&self) -> &str; 24 | fn rust_type(&self) -> &str; 25 | fn rust_type_init(&self) -> &str; 26 | } 27 | 28 | pub trait PropertyPrivate { 29 | fn is_object(&self) -> bool; 30 | fn is_complex(&self) -> bool; 31 | fn c_get_type(&self) -> String; 32 | } 33 | 34 | pub trait SimpleTypePrivate { 35 | fn name(&self) -> &str; 36 | fn cpp_set_type(&self) -> &str; 37 | fn c_set_type(&self) -> &str; 38 | fn rust_type(&self) -> &str; 39 | fn rust_type_init(&self) -> &str; 40 | fn is_complex(&self) -> bool; 41 | } 42 | 43 | pub trait ItemPropertyPrivate { 44 | fn is_complex(&self) -> bool; 45 | fn cpp_set_type(&self) -> String; 46 | fn c_get_type(&self) -> String; 47 | fn c_set_type(&self) -> &str; 48 | } 49 | -------------------------------------------------------------------------------- /templates/qt_quick/src/Bindings.cpp: -------------------------------------------------------------------------------- 1 | /* generated by rust_qt_binding_generator */ 2 | #include "Bindings.h" 3 | 4 | namespace { 5 | 6 | typedef void (*qstring_set)(QString* val, const char* utf8, int nbytes); 7 | void set_qstring(QString* val, const char* utf8, int nbytes) { 8 | *val = QString::fromUtf8(utf8, nbytes); 9 | } 10 | inline void simpleMessageChanged(Simple* o) 11 | { 12 | Q_EMIT o->messageChanged(); 13 | } 14 | } 15 | extern "C" { 16 | Simple::Private* simple_new(Simple*, void (*)(Simple*)); 17 | void simple_free(Simple::Private*); 18 | void simple_message_get(const Simple::Private*, QString*, qstring_set); 19 | void simple_message_set(Simple::Private*, const ushort *str, int len); 20 | }; 21 | 22 | Simple::Simple(bool /*owned*/, QObject *parent): 23 | QObject(parent), 24 | m_d(nullptr), 25 | m_ownsPrivate(false) 26 | { 27 | } 28 | 29 | Simple::Simple(QObject *parent): 30 | QObject(parent), 31 | m_d(simple_new(this, 32 | simpleMessageChanged)), 33 | m_ownsPrivate(true) 34 | { 35 | } 36 | 37 | Simple::~Simple() { 38 | if (m_ownsPrivate) { 39 | simple_free(m_d); 40 | } 41 | } 42 | QString Simple::message() const 43 | { 44 | QString v; 45 | simple_message_get(m_d, &v, set_qstring); 46 | return v; 47 | } 48 | void Simple::setMessage(const QString& v) { 49 | simple_message_set(m_d, reinterpret_cast(v.data()), v.size()); 50 | } 51 | -------------------------------------------------------------------------------- /templates/qt_widgets/src/Bindings.cpp: -------------------------------------------------------------------------------- 1 | /* generated by rust_qt_binding_generator */ 2 | #include "Bindings.h" 3 | 4 | namespace { 5 | 6 | typedef void (*qstring_set)(QString* val, const char* utf8, int nbytes); 7 | void set_qstring(QString* val, const char* utf8, int nbytes) { 8 | *val = QString::fromUtf8(utf8, nbytes); 9 | } 10 | inline void simpleMessageChanged(Simple* o) 11 | { 12 | Q_EMIT o->messageChanged(); 13 | } 14 | } 15 | extern "C" { 16 | Simple::Private* simple_new(Simple*, void (*)(Simple*)); 17 | void simple_free(Simple::Private*); 18 | void simple_message_get(const Simple::Private*, QString*, qstring_set); 19 | void simple_message_set(Simple::Private*, const ushort *str, int len); 20 | }; 21 | 22 | Simple::Simple(bool /*owned*/, QObject *parent): 23 | QObject(parent), 24 | m_d(nullptr), 25 | m_ownsPrivate(false) 26 | { 27 | } 28 | 29 | Simple::Simple(QObject *parent): 30 | QObject(parent), 31 | m_d(simple_new(this, 32 | simpleMessageChanged)), 33 | m_ownsPrivate(true) 34 | { 35 | } 36 | 37 | Simple::~Simple() { 38 | if (m_ownsPrivate) { 39 | simple_free(m_d); 40 | } 41 | } 42 | QString Simple::message() const 43 | { 44 | QString v; 45 | simple_message_get(m_d, &v, set_qstring); 46 | return v; 47 | } 48 | void Simple::setMessage(const QString& v) { 49 | simple_message_set(m_d, reinterpret_cast(v.data()), v.size()); 50 | } 51 | -------------------------------------------------------------------------------- /demo/qml/FibonacciList.qml: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Jos van den Oever 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License as 6 | * published by the Free Software Foundation; either version 2 of 7 | * the License or (at your option) version 3 or any later version 8 | * accepted by the membership of KDE e.V. (or its successor approved 9 | * by the membership of KDE e.V.), which shall act as a proxy 10 | * defined in Section 14 of version 3 of the license. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | import QtQuick 2.6 22 | import QtQml.Models 2.2 23 | import QtQuick.Controls 1.5 24 | import QtQuick.Layouts 1.3 25 | 26 | TableView { 27 | model: demo.fibonacciList 28 | TableViewColumn { 29 | role: "row" 30 | title: qsTr("Row") 31 | width: 100 32 | } 33 | TableViewColumn { 34 | role: "fibonacciNumber" 35 | title: qsTr("Fibonacci number") 36 | width: 100 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /tests/test_object_rust.cpp: -------------------------------------------------------------------------------- 1 | /* generated by rust_qt_binding_generator */ 2 | #include "test_object_rust.h" 3 | 4 | namespace { 5 | 6 | typedef void (*qstring_set)(QString* val, const char* utf8, int nbytes); 7 | void set_qstring(QString* val, const char* utf8, int nbytes) { 8 | *val = QString::fromUtf8(utf8, nbytes); 9 | } 10 | inline void personUserNameChanged(Person* o) 11 | { 12 | Q_EMIT o->userNameChanged(); 13 | } 14 | } 15 | extern "C" { 16 | Person::Private* person_new(Person*, void (*)(Person*)); 17 | void person_free(Person::Private*); 18 | void person_user_name_get(const Person::Private*, QString*, qstring_set); 19 | void person_user_name_set(Person::Private*, const ushort *str, int len); 20 | }; 21 | 22 | Person::Person(bool /*owned*/, QObject *parent): 23 | QObject(parent), 24 | m_d(nullptr), 25 | m_ownsPrivate(false) 26 | { 27 | } 28 | 29 | Person::Person(QObject *parent): 30 | QObject(parent), 31 | m_d(person_new(this, 32 | personUserNameChanged)), 33 | m_ownsPrivate(true) 34 | { 35 | } 36 | 37 | Person::~Person() { 38 | if (m_ownsPrivate) { 39 | person_free(m_d); 40 | } 41 | } 42 | QString Person::userName() const 43 | { 44 | QString v; 45 | person_user_name_get(m_d, &v, set_qstring); 46 | return v; 47 | } 48 | void Person::setUserName(const QString& v) { 49 | person_user_name_set(m_d, reinterpret_cast(v.data()), v.size()); 50 | } 51 | -------------------------------------------------------------------------------- /demo/qml/FibonacciListKirigami.qml: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Jos van den Oever 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License as 6 | * published by the Free Software Foundation; either version 2 of 7 | * the License or (at your option) version 3 or any later version 8 | * accepted by the membership of KDE e.V. (or its successor approved 9 | * by the membership of KDE e.V.), which shall act as a proxy 10 | * defined in Section 14 of version 3 of the license. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | import QtQuick 2.6 22 | import QtQuick.Controls 2.0 as QQC2 23 | import org.kde.kirigami 2.0 as Kirigami 24 | 25 | Kirigami.ScrollablePage { 26 | ListView { 27 | model: demo.fibonacciList 28 | header: Kirigami.Heading { 29 | text: qsTr("Row") + "\t" + qsTr("Fibonacci number") 30 | } 31 | delegate: Kirigami.BasicListItem { 32 | label: row + "\t" + fibonacciNumber 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /tests/rust_tree/src/implementation.rs: -------------------------------------------------------------------------------- 1 | #![allow(unused_imports)] 2 | #![allow(unused_variables)] 3 | #![allow(dead_code)] 4 | use interface::*; 5 | 6 | #[derive(Default, Clone)] 7 | struct PersonsItem { 8 | user_name: String, 9 | } 10 | 11 | pub struct Persons { 12 | emit: PersonsEmitter, 13 | model: PersonsTree, 14 | list: Vec, 15 | } 16 | 17 | impl PersonsTrait for Persons { 18 | fn new(emit: PersonsEmitter, model: PersonsTree) -> Persons { 19 | Persons { 20 | emit: emit, 21 | model: model, 22 | list: vec![PersonsItem::default(); 10], 23 | } 24 | } 25 | fn emit(&mut self) -> &mut PersonsEmitter { 26 | &mut self.emit 27 | } 28 | fn row_count(&self, index: Option) -> usize { 29 | self.list.len() 30 | } 31 | fn index(&self, index: Option, row: usize) -> usize { 32 | 0 33 | } 34 | fn parent(&self, index: usize) -> Option { 35 | None 36 | } 37 | fn row(&self, index: usize) -> usize { 38 | index 39 | } 40 | fn check_row(&self, index: usize, _row: usize) -> Option { 41 | if index < self.list.len() { 42 | Some(index) 43 | } else { 44 | None 45 | } 46 | } 47 | fn user_name(&self, index: usize) -> &str { 48 | &self.list[index].user_name 49 | } 50 | fn set_user_name(&mut self, index: usize, v: String) -> bool { 51 | self.list[index].user_name = v; 52 | true 53 | } 54 | } 55 | 56 | -------------------------------------------------------------------------------- /demo/qml/FibonacciList2.qml: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Jos van den Oever 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License as 6 | * published by the Free Software Foundation; either version 2 of 7 | * the License or (at your option) version 3 or any later version 8 | * accepted by the membership of KDE e.V. (or its successor approved 9 | * by the membership of KDE e.V.), which shall act as a proxy 10 | * defined in Section 14 of version 3 of the license. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | import QtQuick 2.6 22 | import QtQuick.Controls 2.2 23 | 24 | ListView { 25 | model: demo.fibonacciList 26 | header: Row { 27 | Text { 28 | width: 100 29 | text: qsTr("Row") 30 | } 31 | Text { 32 | text: qsTr("Fibonacci number") 33 | } 34 | } 35 | delegate: Row { 36 | Text { 37 | width: 100 38 | text: row 39 | } 40 | Text { 41 | text: fibonacciNumber 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /demo/src/SortedModel.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Jos van den Oever 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License as 6 | * published by the Free Software Foundation; either version 2 of 7 | * the License or (at your option) version 3 or any later version 8 | * accepted by the membership of KDE e.V. (or its successor approved 9 | * by the membership of KDE e.V.), which shall act as a proxy 10 | * defined in Section 14 of version 3 of the license. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | #include "SortedModel.h" 22 | 23 | bool SortedModel::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const 24 | { 25 | if (QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent)) { 26 | return true; 27 | } 28 | 29 | QModelIndex source_index = sourceModel()->index(source_row, 0, source_parent); 30 | for (int i = 0 ; i < sourceModel()->rowCount(source_index); ++i) { 31 | if (filterAcceptsRow(i, source_index)) return true; 32 | } 33 | 34 | return false; 35 | } 36 | -------------------------------------------------------------------------------- /demo/qml/StyleSwitcher.qml: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Jos van den Oever 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License as 6 | * published by the Free Software Foundation; either version 2 of 7 | * the License or (at your option) version 3 or any later version 8 | * accepted by the membership of KDE e.V. (or its successor approved 9 | * by the membership of KDE e.V.), which shall act as a proxy 10 | * defined in Section 14 of version 3 of the license. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | import QtQuick 2.6 22 | import QtQuick.Controls 1.5 23 | import QtQuick.Layouts 1.3 24 | 25 | RowLayout { 26 | Image { 27 | sourceSize.height: 2* box.height 28 | fillMode: Image.PreserveAspectFit 29 | source: "../rust_qt_binding_generator.svg" 30 | } 31 | ComboBox { 32 | id: box 33 | currentIndex: qtquickIndex 34 | model: styles 35 | textRole: "display" 36 | onActivated: { 37 | if (index !== qtquickIndex) { 38 | widgets.currentIndex = index; 39 | application.close(); 40 | } 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /demo/qml/StyleSwitcher2.qml: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Jos van den Oever 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License as 6 | * published by the Free Software Foundation; either version 2 of 7 | * the License or (at your option) version 3 or any later version 8 | * accepted by the membership of KDE e.V. (or its successor approved 9 | * by the membership of KDE e.V.), which shall act as a proxy 10 | * defined in Section 14 of version 3 of the license. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | import QtQuick 2.6 22 | import QtQuick.Controls 2.2 23 | import QtQuick.Layouts 1.3 24 | 25 | RowLayout { 26 | Image { 27 | sourceSize.height: 2 * box.height 28 | fillMode: Image.PreserveAspectFit 29 | source: "../rust_qt_binding_generator.svg" 30 | } 31 | ComboBox { 32 | id: box 33 | Layout.fillWidth: true 34 | currentIndex: qtquickIndex 35 | model: styles 36 | textRole: "display" 37 | onActivated: { 38 | if (index !== qtquickIndex) { 39 | widgets.currentIndex = index 40 | application.close() 41 | } 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /demo/rust/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | [[package]] 4 | name = "cfg-if" 5 | version = "0.1.10" 6 | source = "registry+https://github.com/rust-lang/crates.io-index" 7 | checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" 8 | 9 | [[package]] 10 | name = "libc" 11 | version = "0.2.92" 12 | source = "registry+https://github.com/rust-lang/crates.io-index" 13 | checksum = "56d855069fafbb9b344c0f962150cd2c1187975cb1c22c1522c240d8c4986714" 14 | 15 | [[package]] 16 | name = "rust" 17 | version = "0.1.0" 18 | dependencies = [ 19 | "libc", 20 | "sysinfo", 21 | ] 22 | 23 | [[package]] 24 | name = "sysinfo" 25 | version = "0.4.1" 26 | source = "registry+https://github.com/rust-lang/crates.io-index" 27 | checksum = "7b2512eb6b954dece4a925c32b9c672b0086ac480491b914e73f399b9fc42733" 28 | dependencies = [ 29 | "cfg-if", 30 | "libc", 31 | "winapi", 32 | ] 33 | 34 | [[package]] 35 | name = "winapi" 36 | version = "0.3.9" 37 | source = "registry+https://github.com/rust-lang/crates.io-index" 38 | checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" 39 | dependencies = [ 40 | "winapi-i686-pc-windows-gnu", 41 | "winapi-x86_64-pc-windows-gnu", 42 | ] 43 | 44 | [[package]] 45 | name = "winapi-i686-pc-windows-gnu" 46 | version = "0.4.0" 47 | source = "registry+https://github.com/rust-lang/crates.io-index" 48 | checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" 49 | 50 | [[package]] 51 | name = "winapi-x86_64-pc-windows-gnu" 52 | version = "0.4.0" 53 | source = "registry+https://github.com/rust-lang/crates.io-index" 54 | checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" 55 | -------------------------------------------------------------------------------- /demo/qml/Fibonacci2.qml: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Jos van den Oever 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License as 6 | * published by the Free Software Foundation; either version 2 of 7 | * the License or (at your option) version 3 or any later version 8 | * accepted by the membership of KDE e.V. (or its successor approved 9 | * by the membership of KDE e.V.), which shall act as a proxy 10 | * defined in Section 14 of version 3 of the license. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | import QtQuick 2.6 22 | import QtQuick.Controls 2.0 23 | import QtQuick.Layouts 1.3 24 | 25 | ColumnLayout { 26 | Text { 27 | text: qsTr("Calculate the nth Fibonacci number") 28 | } 29 | TextField { 30 | id: fibonacciInput 31 | placeholderText: qsTr("Your number") 32 | validator: IntValidator { 33 | bottom: 0 34 | top: 100 35 | } 36 | text: demo.fibonacci.input 37 | onAccepted: { 38 | var val = parseInt(text, 10) 39 | if (val !== demo.fibonacci.input) { 40 | demo.fibonacci.input = val 41 | } 42 | } 43 | } 44 | Text { 45 | text: qsTr("The Fibonacci number: ") + demo.fibonacci.result 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /demo/qml/Fibonacci.qml: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Jos van den Oever 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License as 6 | * published by the Free Software Foundation; either version 2 of 7 | * the License or (at your option) version 3 or any later version 8 | * accepted by the membership of KDE e.V. (or its successor approved 9 | * by the membership of KDE e.V.), which shall act as a proxy 10 | * defined in Section 14 of version 3 of the license. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | import QtQuick 2.6 22 | import QtQuick.Controls 1.5 23 | import QtQuick.Layouts 1.3 24 | 25 | ColumnLayout { 26 | Layout.fillHeight: true 27 | Text { 28 | text: qsTr("Calculate the nth Fibonacci number") 29 | } 30 | TextField { 31 | id: fibonacciInput 32 | placeholderText: qsTr("Your number") 33 | validator: IntValidator { 34 | bottom: 0 35 | top: 100 36 | } 37 | text: demo.fibonacci.input 38 | onAccepted: { 39 | var val = parseInt(text, 10) 40 | if (val !== demo.fibonacci.input) { 41 | demo.fibonacci.input = val 42 | } 43 | } 44 | } 45 | Text { 46 | text: qsTr("The Fibonacci number: ") + demo.fibonacci.result 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /tests/rust_functions/src/implementation.rs: -------------------------------------------------------------------------------- 1 | #![allow(unused_imports)] 2 | #![allow(unused_variables)] 3 | #![allow(dead_code)] 4 | use interface::*; 5 | 6 | pub struct Person { 7 | emit: PersonEmitter, 8 | user_name: String, 9 | } 10 | 11 | impl PersonTrait for Person { 12 | fn new(emit: PersonEmitter) -> Person { 13 | Person { 14 | emit: emit, 15 | user_name: String::new(), 16 | } 17 | } 18 | fn emit(&mut self) -> &mut PersonEmitter { 19 | &mut self.emit 20 | } 21 | fn user_name(&self) -> &str { 22 | &self.user_name 23 | } 24 | fn set_user_name(&mut self, value: String) { 25 | self.user_name = value; 26 | self.emit.user_name_changed(); 27 | } 28 | 29 | fn double_name(&mut self) { 30 | self.user_name = format!("{}{}", self.user_name, self.user_name); 31 | } 32 | 33 | fn append(&mut self, suffix: String, amount: u32) { 34 | for _ in 0..amount { 35 | self.user_name += &suffix; 36 | } 37 | } 38 | 39 | fn greet(&self, name: String) -> String { 40 | format!("Hello {}, my name is {}, how is it going?", name, self.user_name) 41 | } 42 | 43 | fn vowels_in_name(&self) -> u8 { 44 | self.user_name.chars().fold(0, |count, ch| match ch { 45 | 'a'|'e'|'i'|'o'|'u' => count + 1, 46 | _ => count 47 | }) 48 | } 49 | 50 | fn quote(&self, prefix: String, suffix: String) -> String { 51 | format!("{}{}{}", prefix, self.user_name, suffix) 52 | } 53 | fn quote_bytes(&self, prefix: &[u8], suffix: &[u8]) -> Vec { 54 | let prefix = String::from_utf8_lossy(prefix); 55 | let suffix = String::from_utf8_lossy(suffix); 56 | format!("{}{}{}", prefix, self.user_name, suffix).into() 57 | } 58 | } 59 | 60 | -------------------------------------------------------------------------------- /cmake/FindCargo.cmake: -------------------------------------------------------------------------------- 1 | # Find the cargo executable 2 | # 3 | # Defines the following variables 4 | # Cargo_FOUND - True if the cargo executable was found 5 | # Cargo_EXECUTABLE - path of the cargo executable 6 | # Cargo_VERSION - version number of cargo 7 | 8 | #============================================================================= 9 | # Copyright 2017 Friedrich W. H. Kossebau 10 | # 11 | # Distributed under the OSI-approved BSD License (the "License"); 12 | # see accompanying file Copyright.txt for details. 13 | # 14 | # This software is distributed WITHOUT ANY WARRANTY; without even the 15 | # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 16 | # See the License for more information. 17 | #============================================================================= 18 | 19 | find_program(Cargo_EXECUTABLE NAMES cargo) 20 | 21 | if (Cargo_EXECUTABLE) 22 | execute_process(COMMAND "${Cargo_EXECUTABLE}" --version 23 | OUTPUT_VARIABLE Cargo_VERSION_OUTPUT 24 | ERROR_VARIABLE Cargo_VERSION_ERROR 25 | RESULT_VARIABLE Cargo_VERSION_RESULT 26 | ) 27 | if(NOT ${Cargo_VERSION_RESULT} EQUAL 0) 28 | message(SEND_ERROR "Command \"${Cargo_EXECUTABLE} --version\" failed with output:\n${Cargo_VERSION_ERROR}") 29 | else() 30 | # TODO: support also nightly 31 | string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" 32 | Cargo_VERSION "${Cargo_VERSION_OUTPUT}" 33 | ) 34 | endif() 35 | endif() 36 | 37 | include(FindPackageHandleStandardArgs) 38 | find_package_handle_standard_args(Cargo 39 | REQUIRED_VARS Cargo_EXECUTABLE 40 | VERSION_VAR Cargo_VERSION 41 | ) 42 | 43 | mark_as_advanced(Cargo_EXECUTABLE Cargo_VERSION) 44 | 45 | set_package_properties(Cargo PROPERTIES 46 | DESCRIPTION "The Rust package manager" 47 | URL "https://github.com/rust-lang/cargo/" 48 | ) 49 | -------------------------------------------------------------------------------- /demo/src/SortedModel.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Jos van den Oever 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License as 6 | * published by the Free Software Foundation; either version 2 of 7 | * the License or (at your option) version 3 or any later version 8 | * accepted by the membership of KDE e.V. (or its successor approved 9 | * by the membership of KDE e.V.), which shall act as a proxy 10 | * defined in Section 14 of version 3 of the license. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | #ifndef SORTED_MODEL 22 | #define SORTED_MODEL 23 | 24 | #include 25 | #include 26 | 27 | class SortedModel : public QSortFilterProxyModel { 28 | Q_OBJECT 29 | public: 30 | SortedModel() :QSortFilterProxyModel() {} 31 | bool filterAcceptsRow(int source_row, const QModelIndex & source_parent) const override; 32 | Q_INVOKABLE QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override { 33 | return QSortFilterProxyModel::data(index, role); 34 | } 35 | public slots: 36 | void sortByRole(const QString& role, Qt::SortOrder order) { 37 | QHashIterator i(roleNames()); 38 | while (i.hasNext()) { 39 | i.next(); 40 | if (i.value() == role) { 41 | setSortRole(i.key()); 42 | } 43 | } 44 | sort(0, order); 45 | } 46 | }; 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /examples/todos/bindings.json: -------------------------------------------------------------------------------- 1 | { 2 | "cppFile": "src/Bindings.cpp", 3 | "rust": { 4 | "dir": "rust", 5 | "interfaceModule": "interface", 6 | "implementationModule": "implementation" 7 | }, 8 | "objects": { 9 | "Todos": { 10 | "type": "List", 11 | "properties": { 12 | "count": { 13 | "type": "quint64" 14 | }, 15 | "activeCount": { 16 | "type": "quint64" 17 | } 18 | }, 19 | "itemProperties": { 20 | "completed": { 21 | "type": "bool", 22 | "write": true 23 | }, 24 | "description": { 25 | "type": "QString", 26 | "write": true 27 | } 28 | }, 29 | "functions": { 30 | "add": { 31 | "return": "void", 32 | "mut": true, 33 | "arguments": [{ 34 | "name": "description", 35 | "type": "QString" 36 | }] 37 | }, 38 | "remove": { 39 | "return": "bool", 40 | "mut": true, 41 | "arguments": [{ 42 | "name": "index", 43 | "type": "quint64" 44 | }] 45 | }, 46 | "setAll": { 47 | "return": "void", 48 | "mut": true, 49 | "arguments": [{ 50 | "name": "completed", 51 | "type": "bool" 52 | }] 53 | }, 54 | "clearCompleted": { 55 | "return": "void", 56 | "mut": true, 57 | "arguments": [] 58 | } 59 | } 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /templates/qt_widgets_cargo/src/main.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 250 10 | 150 11 | 12 | 13 | 14 | Widgets Template 15 | 16 | 17 | 18 | 19 | 20 | 70 21 | 40 22 | 111 23 | 30 24 | 25 | 26 | 27 | Update Status 28 | 29 | 30 | 31 | 32 | 33 | 30 34 | 0 35 | 191 36 | 32 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 0 45 | 0 46 | 250 47 | 30 48 | 49 | 50 | 51 | 52 | &File 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | &Quit 62 | 63 | 64 | Ctrl+Q 65 | 66 | 67 | 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /tests/rust_objects/src/implementation.rs: -------------------------------------------------------------------------------- 1 | #![allow(unused_imports)] 2 | #![allow(unused_variables)] 3 | #![allow(dead_code)] 4 | use interface::*; 5 | 6 | pub struct Group { 7 | emit: GroupEmitter, 8 | person: Person, 9 | } 10 | 11 | impl GroupTrait for Group { 12 | fn new(emit: GroupEmitter, person: Person) -> Group { 13 | Group { 14 | emit: emit, 15 | person: person, 16 | } 17 | } 18 | fn emit(&mut self) -> &mut GroupEmitter { 19 | &mut self.emit 20 | } 21 | fn person(&self) -> &Person { 22 | &self.person 23 | } 24 | fn person_mut(&mut self) -> &mut Person { 25 | &mut self.person 26 | } 27 | } 28 | 29 | pub struct InnerObject { 30 | emit: InnerObjectEmitter, 31 | description: String, 32 | } 33 | 34 | impl InnerObjectTrait for InnerObject { 35 | fn new(emit: InnerObjectEmitter) -> InnerObject { 36 | InnerObject { 37 | emit: emit, 38 | description: String::new(), 39 | } 40 | } 41 | fn emit(&mut self) -> &mut InnerObjectEmitter { 42 | &mut self.emit 43 | } 44 | fn description(&self) -> &str { 45 | &self.description 46 | } 47 | fn set_description(&mut self, value: String) { 48 | self.description = value; 49 | self.emit.description_changed(); 50 | } 51 | } 52 | 53 | pub struct Person { 54 | emit: PersonEmitter, 55 | object: InnerObject, 56 | } 57 | 58 | impl PersonTrait for Person { 59 | fn new(emit: PersonEmitter, object: InnerObject) -> Person { 60 | Person { 61 | emit: emit, 62 | object: object, 63 | } 64 | } 65 | fn emit(&mut self) -> &mut PersonEmitter { 66 | &mut self.emit 67 | } 68 | fn object(&self) -> &InnerObject { 69 | &self.object 70 | } 71 | fn object_mut(&mut self) -> &mut InnerObject { 72 | &mut self.object 73 | } 74 | } 75 | 76 | -------------------------------------------------------------------------------- /demo/qml/FileTreeView.qml: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Jos van den Oever 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License as 6 | * published by the Free Software Foundation; either version 2 of 7 | * the License or (at your option) version 3 or any later version 8 | * accepted by the membership of KDE e.V. (or its successor approved 9 | * by the membership of KDE e.V.), which shall act as a proxy 10 | * defined in Section 14 of version 3 of the license. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | import QtQuick 2.6 22 | import QtQml.Models 2.2 23 | import QtQuick.Controls 1.5 24 | import QtQuick.Layouts 1.3 25 | 26 | TreeView { 27 | id: treeView 28 | model: sortedFileSystem 29 | sortIndicatorVisible: true 30 | alternatingRowColors: true 31 | selection: selectionModel 32 | TableViewColumn { 33 | title: "Name" 34 | role: "fileName" 35 | } 36 | TableViewColumn { 37 | title: "Size" 38 | role: "fileSize" 39 | } 40 | Component.onCompleted: { 41 | var root = treeView.rootIndex 42 | var first = sortedFileSystem.index(0, 0, root) 43 | treeView.expand(first) 44 | } 45 | onSortIndicatorColumnChanged: sort() 46 | onSortIndicatorOrderChanged: sort() 47 | function sort() { 48 | var role = getColumn(treeView.sortIndicatorColumn).role 49 | model.sortByRole(role, treeView.sortIndicatorOrder) 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /tests/test_object.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Jos van den Oever 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License as 6 | * published by the Free Software Foundation; either version 2 of 7 | * the License or (at your option) version 3 or any later version 8 | * accepted by the membership of KDE e.V. (or its successor approved 9 | * by the membership of KDE e.V.), which shall act as a proxy 10 | * defined in Section 14 of version 3 of the license. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | #include "test_object_rust.h" 22 | #include 23 | #include 24 | 25 | class TestRustObject : public QObject 26 | { 27 | Q_OBJECT 28 | private slots: 29 | void testConstructor(); 30 | void testStringGetter(); 31 | void testStringSetter(); 32 | }; 33 | 34 | void TestRustObject::testConstructor() 35 | { 36 | Person person; 37 | } 38 | 39 | void TestRustObject::testStringGetter() 40 | { 41 | Person person; 42 | person.setUserName("Konqi"); 43 | } 44 | 45 | void TestRustObject::testStringSetter() 46 | { 47 | // GIVEN 48 | Person person; 49 | QSignalSpy spy(&person, &Person::userNameChanged); 50 | 51 | // WHEN 52 | person.setUserName("Konqi"); 53 | 54 | // THEN 55 | QVERIFY(spy.isValid()); 56 | QCOMPARE(spy.count(), 1); 57 | QCOMPARE(person.userName(), QString("Konqi")); 58 | } 59 | 60 | QTEST_MAIN(TestRustObject) 61 | #include "test_object.moc" 62 | -------------------------------------------------------------------------------- /demo/qml/demo-qtquick2.qml: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Jos van den Oever 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License as 6 | * published by the Free Software Foundation; either version 2 of 7 | * the License or (at your option) version 3 or any later version 8 | * accepted by the membership of KDE e.V. (or its successor approved 9 | * by the membership of KDE e.V.), which shall act as a proxy 10 | * defined in Section 14 of version 3 of the license. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | import QtQuick 2.6 22 | import QtQuick.Controls 2.0 23 | import QtQuick.Layouts 1.3 24 | 25 | ApplicationWindow { 26 | id: application 27 | property string initialTab: "style" 28 | property int qtquickIndex: 0 29 | visible: true 30 | width: 800 31 | height: 640 32 | header: TabBar { 33 | id: bar 34 | width: parent.width 35 | TabButton { 36 | text: "object" 37 | } 38 | TabButton { 39 | text: "list" 40 | } 41 | TabButton { 42 | text: "tree" 43 | } 44 | } 45 | 46 | footer: Rectangle { 47 | height: statusBar.height 48 | width: parent.width 49 | StyleSwitcher2 { 50 | id: statusBar 51 | width: parent.width 52 | } 53 | } 54 | StackLayout { 55 | anchors.fill: parent 56 | currentIndex: bar.currentIndex 57 | Fibonacci2 {} 58 | FibonacciList2 {} 59 | FileTreeView2 {} 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /tests/test_objects_rust.h: -------------------------------------------------------------------------------- 1 | /* generated by rust_qt_binding_generator */ 2 | #ifndef TEST_OBJECTS_RUST_H 3 | #define TEST_OBJECTS_RUST_H 4 | 5 | #include 6 | #include 7 | 8 | class Group; 9 | class InnerObject; 10 | class Person; 11 | 12 | class Group : public QObject 13 | { 14 | Q_OBJECT 15 | friend class Person; 16 | public: 17 | class Private; 18 | private: 19 | Person* const m_person; 20 | Private * m_d; 21 | bool m_ownsPrivate; 22 | Q_PROPERTY(Person* person READ person NOTIFY personChanged FINAL) 23 | explicit Group(bool owned, QObject *parent); 24 | public: 25 | explicit Group(QObject *parent = nullptr); 26 | ~Group(); 27 | const Person* person() const; 28 | Person* person(); 29 | Q_SIGNALS: 30 | void personChanged(); 31 | }; 32 | 33 | class InnerObject : public QObject 34 | { 35 | Q_OBJECT 36 | friend class Group; 37 | friend class Person; 38 | public: 39 | class Private; 40 | private: 41 | Private * m_d; 42 | bool m_ownsPrivate; 43 | Q_PROPERTY(QString description READ description WRITE setDescription NOTIFY descriptionChanged FINAL) 44 | explicit InnerObject(bool owned, QObject *parent); 45 | public: 46 | explicit InnerObject(QObject *parent = nullptr); 47 | ~InnerObject(); 48 | QString description() const; 49 | void setDescription(const QString& v); 50 | Q_SIGNALS: 51 | void descriptionChanged(); 52 | }; 53 | 54 | class Person : public QObject 55 | { 56 | Q_OBJECT 57 | friend class Group; 58 | public: 59 | class Private; 60 | private: 61 | InnerObject* const m_object; 62 | Private * m_d; 63 | bool m_ownsPrivate; 64 | Q_PROPERTY(InnerObject* object READ object NOTIFY objectChanged FINAL) 65 | explicit Person(bool owned, QObject *parent); 66 | public: 67 | explicit Person(QObject *parent = nullptr); 68 | ~Person(); 69 | const InnerObject* object() const; 70 | InnerObject* object(); 71 | Q_SIGNALS: 72 | void objectChanged(); 73 | }; 74 | #endif // TEST_OBJECTS_RUST_H 75 | -------------------------------------------------------------------------------- /tests/rust_list/src/implementation.rs: -------------------------------------------------------------------------------- 1 | #![allow(unused_imports)] 2 | #![allow(unused_variables)] 3 | #![allow(dead_code)] 4 | use interface::*; 5 | 6 | #[derive(Default, Clone)] 7 | struct PersonsItem { 8 | user_name: String, 9 | age: u8, 10 | } 11 | 12 | pub struct Persons { 13 | emit: PersonsEmitter, 14 | model: PersonsList, 15 | list: Vec, 16 | } 17 | 18 | impl PersonsTrait for Persons { 19 | fn new(emit: PersonsEmitter, model: PersonsList) -> Persons { 20 | Persons { 21 | emit: emit, 22 | model: model, 23 | list: vec![PersonsItem::default(); 10], 24 | } 25 | } 26 | fn emit(&mut self) -> &mut PersonsEmitter { 27 | &mut self.emit 28 | } 29 | fn row_count(&self) -> usize { 30 | self.list.len() 31 | } 32 | fn user_name(&self, index: usize) -> &str { 33 | &self.list[index].user_name 34 | } 35 | fn set_user_name(&mut self, index: usize, v: String) -> bool { 36 | self.list[index].user_name = v; 37 | true 38 | } 39 | } 40 | 41 | pub struct NoRole { 42 | emit: NoRoleEmitter, 43 | model: NoRoleList, 44 | list: Vec 45 | } 46 | 47 | impl NoRoleTrait for NoRole { 48 | fn new(emit: NoRoleEmitter, model: NoRoleList) -> NoRole { 49 | NoRole { 50 | emit: emit, 51 | model: model, 52 | list: vec![PersonsItem::default(); 10], 53 | } 54 | } 55 | fn emit(&mut self) -> &mut NoRoleEmitter { 56 | &mut self.emit 57 | } 58 | fn row_count(&self) -> usize { 59 | self.list.len() 60 | } 61 | fn user_name(&self, index: usize) -> &str { 62 | &self.list[index].user_name 63 | } 64 | fn set_user_name(&mut self, index: usize, v: String) -> bool { 65 | self.list[index].user_name = v; 66 | true 67 | } 68 | fn user_age(&self, index: usize) -> u8 { 69 | self.list[index].age 70 | } 71 | fn set_user_age(&mut self, index: usize, v: u8) -> bool { 72 | self.list[index].age = v; 73 | true 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /demo/qml/demo-kirigami2.qml: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Jos van den Oever 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License as 6 | * published by the Free Software Foundation; either version 2 of 7 | * the License or (at your option) version 3 or any later version 8 | * accepted by the membership of KDE e.V. (or its successor approved 9 | * by the membership of KDE e.V.), which shall act as a proxy 10 | * defined in Section 14 of version 3 of the license. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | import QtQuick 2.1 22 | import QtQuick.Controls 2.0 as QQC2 23 | import org.kde.kirigami 2.0 as Kirigami 24 | import QtQuick.Layouts 1.3 25 | 26 | Kirigami.ApplicationWindow { 27 | id: application 28 | property string initialTab: "style" 29 | property int qtquickIndex: 0 30 | visible: true 31 | width: 800 32 | height: 640 33 | header: QQC2.TabBar { 34 | id: bar 35 | width: parent.width 36 | QQC2.TabButton { 37 | text: "object" 38 | } 39 | QQC2.TabButton { 40 | text: "list" 41 | } 42 | QQC2.TabButton { 43 | text: "tree" 44 | } 45 | } 46 | 47 | footer: Rectangle { 48 | height: statusBar.height 49 | width: parent.width 50 | StyleSwitcher2 { 51 | id: statusBar 52 | width: parent.width 53 | } 54 | } 55 | StackLayout { 56 | anchors.fill: parent 57 | currentIndex: bar.currentIndex 58 | Fibonacci2 {} 59 | FibonacciListKirigami {} 60 | FileTreeViewKirigami {} 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /demo/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(CMAKE_AUTORCC ON) 2 | 3 | # generate c++ and rust code from bindings.json 4 | add_custom_command( 5 | OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/rust/src/interface.rs" 6 | "${CMAKE_CURRENT_SOURCE_DIR}/src/Bindings.h" 7 | # if the cpp file is marked GENERATED, CMake will not check it for moc 8 | # "${CMAKE_CURRENT_SOURCE_DIR}/src/Bindings.cpp" 9 | COMMAND ${RustQtBindingGenerator_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/bindings.json" 10 | DEPENDS rust_qt_binding_generator bindings.json 11 | ) 12 | 13 | SET(RUST_DIR "${CMAKE_CURRENT_SOURCE_DIR}/rust") 14 | if (MSVC) 15 | SET(RUST_LIB "${RUST_DIR}/${RUST_TARGET_DIR}/rust.lib") 16 | else() 17 | SET(RUST_LIB "${RUST_DIR}/${RUST_TARGET_DIR}/librust.a") 18 | endif() 19 | 20 | # compile the rust code into a static library 21 | add_custom_command( 22 | OUTPUT "${RUST_LIB}" 23 | COMMAND ${Cargo_EXECUTABLE} build ${RUST_BUILD_FLAG} 24 | DEPENDS rust/src/lib.rs 25 | rust/src/implementation/mod.rs 26 | rust/src/implementation/time_series.rs 27 | rust/src/implementation/fibonacci.rs 28 | rust/src/implementation/processes.rs 29 | rust/src/interface.rs 30 | WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/rust" 31 | ) 32 | add_custom_target(rust_target DEPENDS "${RUST_LIB}") 33 | 34 | list(APPEND DemoLibs "${RUST_LIB}") 35 | list(APPEND DemoLibs Qt5::Widgets Qt5::Svg Threads::Threads ${DL_LIBRARY}) 36 | if (Qt5Quick_FOUND) 37 | list(APPEND DemoLibs Qt5::Quick) 38 | endif() 39 | if (Qt5QuickControls2_FOUND) 40 | add_definitions(-DQTQUICKCONTROLS2) 41 | list(APPEND DemoLibs Qt5::QuickControls2) 42 | endif() 43 | if (Qt5Charts_FOUND) 44 | list(APPEND DemoLibs Qt5::Charts) 45 | endif() 46 | if (KF5Kirigami2_FOUND) 47 | add_definitions(-DKIRIGAMI2) 48 | endif() 49 | 50 | if (ECM_FOUND) 51 | ecm_create_qm_loader(Demo_QM_LOADER rqbgdemo_qt) 52 | endif() 53 | 54 | set(Demo_SRCS src/main.cpp src/Bindings.cpp src/SortedModel.cpp 55 | resource_file.qrc ${Demo_QM_LOADER}) 56 | 57 | add_executable(Demo ${Demo_SRCS}) 58 | add_dependencies(Demo rust_target) 59 | 60 | target_link_libraries(Demo ${DemoLibs}) 61 | 62 | set_target_properties(Demo PROPERTIES 63 | CXX_STANDARD 11 64 | CXX_STANDARD_REQUIRED ON 65 | ) 66 | -------------------------------------------------------------------------------- /demo/qml/chart.qml: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Jos van den Oever 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License as 6 | * published by the Free Software Foundation; either version 2 of 7 | * the License or (at your option) version 3 or any later version 8 | * accepted by the membership of KDE e.V. (or its successor approved 9 | * by the membership of KDE e.V.), which shall act as a proxy 10 | * defined in Section 14 of version 3 of the license. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | import QtQuick 2.6 22 | import QtCharts 2.2 23 | 24 | Item { 25 | ChartView { 26 | id: chart 27 | anchors.fill: parent 28 | Component.onCompleted: { 29 | legend.alignment = Qt.AlignBottom 30 | } 31 | 32 | antialiasing: true 33 | 34 | ValueAxis { 35 | id: axisX 36 | titleText: qsTr("time [s]") 37 | labelFormat: "%.1f" 38 | } 39 | 40 | ValueAxis { 41 | id: axisY 42 | titleText: qsTr("electric potential [V]") 43 | labelFormat: "%.1f" 44 | } 45 | 46 | LineSeries { 47 | id: sin 48 | name: "sin" 49 | axisX: axisX 50 | axisY: axisY 51 | } 52 | 53 | VXYModelMapper { 54 | model: demo.timeSeries 55 | xColumn: 0 56 | yColumn: 1 57 | series: sin 58 | } 59 | 60 | LineSeries { 61 | id: cos 62 | name: "cos" 63 | axisX: axisX 64 | axisY: axisY 65 | } 66 | 67 | VXYModelMapper { 68 | model: demo.timeSeries 69 | xColumn: 0 70 | yColumn: 2 71 | series: cos 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /tests/test_tree.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Jos van den Oever 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License as 6 | * published by the Free Software Foundation; either version 2 of 7 | * the License or (at your option) version 3 or any later version 8 | * accepted by the membership of KDE e.V. (or its successor approved 9 | * by the membership of KDE e.V.), which shall act as a proxy 10 | * defined in Section 14 of version 3 of the license. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | #include "test_list_rust.h" 22 | #include 23 | #include 24 | 25 | class TestRustTree : public QObject 26 | { 27 | Q_OBJECT 28 | private slots: 29 | void testConstructor(); 30 | void testStringGetter(); 31 | void testStringSetter(); 32 | }; 33 | 34 | void TestRustTree::testConstructor() 35 | { 36 | Persons persons; 37 | } 38 | 39 | void TestRustTree::testStringGetter() 40 | { 41 | Persons persons; 42 | QCOMPARE(persons.rowCount(), 10); 43 | QVariant value = persons.data(persons.index(0,0)); 44 | // value should be empty string in default implementation 45 | QVERIFY(value.isValid()); 46 | QCOMPARE(value.type(), QVariant::String); 47 | QCOMPARE(value.toString(), QString()); 48 | } 49 | 50 | void TestRustTree::testStringSetter() 51 | { 52 | // GIVEN 53 | Persons persons; 54 | QSignalSpy spy(&persons, &Persons::dataChanged); 55 | 56 | // WHEN 57 | const QModelIndex index(persons.index(0,0)); 58 | const bool set = persons.setData(index, "Konqi"); 59 | 60 | // THEN 61 | QVERIFY(set); 62 | QVERIFY(spy.isValid()); 63 | QCOMPARE(spy.count(), 1); 64 | QVariant value = persons.data(persons.index(0,0)); 65 | QCOMPARE(value.toString(), QString("Konqi")); 66 | } 67 | 68 | QTEST_MAIN(TestRustTree) 69 | #include "test_tree.moc" 70 | -------------------------------------------------------------------------------- /tests/test_tree_rust.h: -------------------------------------------------------------------------------- 1 | /* generated by rust_qt_binding_generator */ 2 | #ifndef TEST_TREE_RUST_H 3 | #define TEST_TREE_RUST_H 4 | 5 | #include 6 | #include 7 | 8 | class Persons; 9 | 10 | class Persons : public QAbstractItemModel 11 | { 12 | Q_OBJECT 13 | public: 14 | class Private; 15 | private: 16 | Private * m_d; 17 | bool m_ownsPrivate; 18 | explicit Persons(bool owned, QObject *parent); 19 | public: 20 | explicit Persons(QObject *parent = nullptr); 21 | ~Persons(); 22 | 23 | int columnCount(const QModelIndex &parent = QModelIndex()) const override; 24 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; 25 | QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override; 26 | QModelIndex parent(const QModelIndex &index) const override; 27 | bool hasChildren(const QModelIndex &parent = QModelIndex()) const override; 28 | int rowCount(const QModelIndex &parent = QModelIndex()) const override; 29 | bool canFetchMore(const QModelIndex &parent) const override; 30 | void fetchMore(const QModelIndex &parent) override; 31 | Qt::ItemFlags flags(const QModelIndex &index) const override; 32 | void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override; 33 | int role(const char* name) const; 34 | QHash roleNames() const override; 35 | QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; 36 | bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole) override; 37 | Q_INVOKABLE bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) override; 38 | Q_INVOKABLE bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override; 39 | bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override; 40 | Q_INVOKABLE QString userName(const QModelIndex& index) const; 41 | Q_INVOKABLE bool setUserName(const QModelIndex& index, const QString& value); 42 | 43 | Q_SIGNALS: 44 | // new data is ready to be made available to the model with fetchMore() 45 | void newDataReady(const QModelIndex &parent) const; 46 | private: 47 | QHash, QVariant> m_headerData; 48 | void initHeaderData(); 49 | void updatePersistentIndexes(); 50 | Q_SIGNALS: 51 | }; 52 | #endif // TEST_TREE_RUST_H 53 | -------------------------------------------------------------------------------- /templates/qt_widgets/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project (my_rust_qt_widgets_project) 2 | 3 | cmake_minimum_required(VERSION 3.10 FATAL_ERROR) 4 | cmake_policy(SET CMP0046 NEW) 5 | cmake_policy(SET CMP0063 NEW) 6 | cmake_policy(SET CMP0071 NEW) 7 | LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") 8 | 9 | string(TOUPPER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_UPPER) 10 | if(CMAKE_BUILD_TYPE_UPPER STREQUAL DEBUG) 11 | set(RUST_TARGET_DIR target/debug/) 12 | set(RUST_BUILD_FLAG) 13 | else() 14 | set(RUST_TARGET_DIR target/release/) 15 | set(RUST_BUILD_FLAG --release) 16 | endif() 17 | 18 | ### find dependencies ### 19 | 20 | include(FeatureSummary) 21 | find_package(Cargo REQUIRED) 22 | find_package(Rust REQUIRED) 23 | set(CMAKE_THREAD_PREFER_PTHREAD TRUE) 24 | find_package(Threads REQUIRED) 25 | 26 | set(QT_MIN_VERSION "5.6.0") 27 | find_package(Qt5 ${QT_MIN_VERSION} CONFIG 28 | REQUIRED COMPONENTS 29 | Widgets 30 | ) 31 | set(CMAKE_AUTOMOC ON) 32 | set(CMAKE_AUTOUIC ON) 33 | set(CMAKE_AUTORCC ON) 34 | find_package(RustQtBindingGenerator REQUIRED) 35 | 36 | feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES) 37 | 38 | ### build commands ### 39 | 40 | SET(RUST_DIR "${CMAKE_CURRENT_SOURCE_DIR}/rust") 41 | if (MSVC) 42 | SET(RUST_LIB "${RUST_DIR}/${RUST_TARGET_DIR}/rust.lib") 43 | else() 44 | SET(RUST_LIB "${RUST_DIR}/${RUST_TARGET_DIR}/librust.a") 45 | endif() 46 | 47 | # generate c++ and rust code from bindings.json 48 | add_custom_command( 49 | OUTPUT "${RUST_DIR}/src/interface.rs" 50 | "${CMAKE_CURRENT_SOURCE_DIR}/src/Bindings.h" 51 | "${CMAKE_CURRENT_SOURCE_DIR}/src/Bindings.cpp" 52 | COMMAND "${RustQtBindingGenerator_EXECUTABLE}" 53 | "${CMAKE_CURRENT_SOURCE_DIR}/bindings.json" 54 | DEPENDS bindings.json 55 | ) 56 | 57 | # compile the rust code into a static library 58 | add_custom_command( 59 | OUTPUT "${RUST_LIB}" 60 | COMMAND ${Cargo_EXECUTABLE} build ${RUST_BUILD_FLAG} 61 | DEPENDS rust/src/lib.rs 62 | rust/src/implementation.rs 63 | rust/src/interface.rs 64 | WORKING_DIRECTORY "${RUST_DIR}" 65 | ) 66 | add_custom_target(rust_target DEPENDS "${RUST_LIB}") 67 | 68 | list(APPEND Libs "${RUST_LIB}") 69 | list(APPEND Libs Qt5::Widgets Threads::Threads ${CMAKE_DL_LIBS}) 70 | set(SRCS src/main.cpp src/Bindings.cpp) 71 | add_executable(MyExe ${SRCS}) 72 | add_dependencies(MyExe rust_target) 73 | target_link_libraries(MyExe ${Libs}) 74 | set_target_properties(MyExe PROPERTIES 75 | CXX_STANDARD 11 76 | CXX_STANDARD_REQUIRED ON 77 | ) 78 | -------------------------------------------------------------------------------- /tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | set(GENERATOR "${RustQtBindingGenerator_EXECUTABLE}") 3 | include_directories("${CMAKE_CURRENT_BINARY_DIR}") 4 | 5 | add_custom_target("clean-rust") 6 | 7 | function(rust_test NAME DIRECTORY) 8 | set(SRC "${CMAKE_CURRENT_SOURCE_DIR}") 9 | set(DIR "${SRC}/${DIRECTORY}") 10 | if (MSVC) 11 | SET(RUST_LIB "${DIR}/${RUST_TARGET_DIR}/rust.lib") 12 | else() 13 | SET(RUST_LIB "${DIR}/${RUST_TARGET_DIR}/librust.a") 14 | endif() 15 | 16 | set_property(SOURCE "${SRC}/${NAME}_rust.h" PROPERTY SKIP_AUTOGEN OFF) 17 | add_custom_command( 18 | OUTPUT "${DIR}/src/interface.rs" 19 | "${SRC}/${NAME}_rust.h" 20 | "${SRC}/${NAME}_rust.cpp" 21 | COMMAND "${GENERATOR}" "${SRC}/${NAME}.json" 22 | MAIN_DEPENDENCY "${NAME}.json" 23 | DEPENDS rust_qt_binding_generator 24 | ) 25 | add_custom_command( 26 | OUTPUT "${RUST_LIB}" 27 | COMMAND ${Cargo_EXECUTABLE} build ${RUST_BUILD_FLAG} 28 | DEPENDS "${DIR}/src/lib.rs" 29 | "${DIR}/src/implementation.rs" 30 | "${DIR}/src/interface.rs" 31 | WORKING_DIRECTORY "${DIR}" 32 | ) 33 | add_custom_target("test_${DIRECTORY}" 34 | DEPENDS "${RUST_LIB}") 35 | 36 | add_executable("${NAME}" "${NAME}.cpp" "${NAME}_rust.cpp" "${NAME}_rust.h") 37 | set_target_properties("${NAME}" PROPERTIES 38 | CXX_STANDARD 11 39 | CXX_STANDARD_REQUIRED ON 40 | ) 41 | add_dependencies("${NAME}" "test_${DIRECTORY}") 42 | target_link_libraries("${NAME}" 43 | Qt5::Core 44 | Qt5::Test 45 | "${RUST_LIB}" 46 | Threads::Threads ${DL_LIBRARY} 47 | ) 48 | 49 | add_test("build_${NAME}" 50 | "${CMAKE_COMMAND}" --build ${CMAKE_BINARY_DIR} --target "${NAME}") 51 | add_test("${NAME}" "${NAME}") 52 | set_tests_properties("${NAME}" PROPERTIES DEPENDS "build_${NAME}") 53 | 54 | add_custom_command( 55 | OUTPUT "clean_${NAME}" 56 | COMMAND ${Cargo_EXECUTABLE} clean 57 | WORKING_DIRECTORY "${DIR}" 58 | ) 59 | add_custom_target("clean-${NAME}" DEPENDS "clean_${NAME}") 60 | add_dependencies("clean-rust" "clean-${NAME}") 61 | 62 | 63 | endfunction(rust_test) 64 | 65 | rust_test(test_object rust_object) 66 | rust_test(test_object_types rust_object_types) 67 | rust_test(test_list rust_list) 68 | rust_test(test_list_types rust_list_types) 69 | rust_test(test_tree rust_tree) 70 | rust_test(test_objects rust_objects) 71 | rust_test(test_functions rust_functions) 72 | -------------------------------------------------------------------------------- /templates/qt_quick/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project (my_rust_qt_quick_project) 2 | 3 | cmake_minimum_required(VERSION 3.10 FATAL_ERROR) 4 | cmake_policy(SET CMP0046 NEW) 5 | cmake_policy(SET CMP0063 NEW) 6 | cmake_policy(SET CMP0071 NEW) 7 | LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") 8 | 9 | string(TOUPPER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_UPPER) 10 | if(CMAKE_BUILD_TYPE_UPPER STREQUAL DEBUG) 11 | set(RUST_TARGET_DIR target/debug/) 12 | set(RUST_BUILD_FLAG) 13 | else() 14 | set(RUST_TARGET_DIR target/release/) 15 | set(RUST_BUILD_FLAG --release) 16 | endif() 17 | 18 | ### find dependencies ### 19 | 20 | include(FeatureSummary) 21 | find_package(Cargo REQUIRED) 22 | find_package(Rust REQUIRED) 23 | set(CMAKE_THREAD_PREFER_PTHREAD TRUE) 24 | find_package(Threads REQUIRED) 25 | 26 | set(QT_MIN_VERSION "5.6.0") 27 | find_package(Qt5 ${QT_MIN_VERSION} CONFIG 28 | REQUIRED COMPONENTS Core Quick 29 | ) 30 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 31 | set(CMAKE_AUTOMOC ON) 32 | set(CMAKE_AUTOUIC ON) 33 | set(CMAKE_AUTORCC ON) 34 | find_package(RustQtBindingGenerator REQUIRED) 35 | 36 | feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES) 37 | 38 | ### build commands ### 39 | 40 | SET(RUST_DIR "${CMAKE_CURRENT_SOURCE_DIR}/rust") 41 | if (MSVC) 42 | SET(RUST_LIB "${RUST_DIR}/${RUST_TARGET_DIR}/rust.lib") 43 | else() 44 | SET(RUST_LIB "${RUST_DIR}/${RUST_TARGET_DIR}/librust.a") 45 | endif() 46 | 47 | # generate c++ and rust code from bindings.json 48 | add_custom_command( 49 | OUTPUT "${RUST_DIR}/src/interface.rs" 50 | "${CMAKE_CURRENT_SOURCE_DIR}/src/Bindings.h" 51 | "${CMAKE_CURRENT_SOURCE_DIR}/src/Bindings.cpp" 52 | COMMAND "${RustQtBindingGenerator_EXECUTABLE}" 53 | "${CMAKE_CURRENT_SOURCE_DIR}/bindings.json" 54 | DEPENDS bindings.json 55 | ) 56 | 57 | # compile the rust code into a static library 58 | add_custom_command( 59 | OUTPUT "${RUST_LIB}" 60 | COMMAND ${Cargo_EXECUTABLE} build ${RUST_BUILD_FLAG} 61 | DEPENDS rust/src/lib.rs 62 | rust/src/implementation.rs 63 | rust/src/interface.rs 64 | WORKING_DIRECTORY "${RUST_DIR}" 65 | ) 66 | add_custom_target(rust_target DEPENDS "${RUST_LIB}") 67 | 68 | list(APPEND Libs "${RUST_LIB}") 69 | list(APPEND Libs Qt5::Core Qt5::Quick Threads::Threads ${CMAKE_DL_LIBS}) 70 | set(SRCS src/main.cpp src/Bindings.cpp "qml.qrc") 71 | add_executable(MyExe ${SRCS}) 72 | add_dependencies(MyExe rust_target) 73 | target_link_libraries(MyExe ${Libs}) 74 | set_target_properties(MyExe PROPERTIES 75 | CXX_STANDARD 11 76 | CXX_STANDARD_REQUIRED ON 77 | ) 78 | -------------------------------------------------------------------------------- /demo/qml/demo.qml: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Jos van den Oever 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License as 6 | * published by the Free Software Foundation; either version 2 of 7 | * the License or (at your option) version 3 or any later version 8 | * accepted by the membership of KDE e.V. (or its successor approved 9 | * by the membership of KDE e.V.), which shall act as a proxy 10 | * defined in Section 14 of version 3 of the license. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | import QtQuick 2.6 22 | import QtQml.Models 2.2 23 | import QtQuick.Controls 1.5 24 | import QtQuick.Layouts 1.3 25 | 26 | ApplicationWindow { 27 | id: application 28 | property string initialTab: "style" 29 | property int qtquickIndex: 0 30 | property var processes: ListModel { 31 | ListElement { 32 | name: "init" 33 | } 34 | } 35 | onInitialTabChanged: { 36 | for (var i = 0; i < tabView.count; ++i) { 37 | if (tabView.getTab(i).title === initialTab) { 38 | tabView.currentIndex = i 39 | } 40 | } 41 | } 42 | width: 640 43 | height: 480 44 | visible: true 45 | ItemSelectionModel { 46 | id: selectionModel 47 | model: sortedFileSystem 48 | } 49 | ItemSelectionModel { 50 | id: processSelection 51 | model: processes 52 | } 53 | statusBar: StatusBar { 54 | StyleSwitcher { 55 | anchors.fill: parent 56 | } 57 | } 58 | TabView { 59 | id: tabView 60 | anchors.fill: parent 61 | Tab { 62 | title: "object" 63 | Fibonacci {} 64 | } 65 | Tab { 66 | title: "list" 67 | FibonacciList {} 68 | } 69 | Tab { 70 | title: "tree" 71 | FileTreeView {} 72 | } 73 | Tab { 74 | title: "processes" 75 | ProcessesTree {} 76 | } 77 | Tab { 78 | id: chartTab 79 | title: "chart" 80 | DataAndChart {} 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /demo/rust/src/implementation/time_series.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Jos van den Oever 2 | // 3 | // This program is free software; you can redistribute it and/or 4 | // modify it under the terms of the GNU General Public License as 5 | // published by the Free Software Foundation; either version 2 of 6 | // the License or (at your option) version 3 or any later version 7 | // accepted by the membership of KDE e.V. (or its successor approved 8 | // by the membership of KDE e.V.), which shall act as a proxy 9 | // defined in Section 14 of version 3 of the license. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | use interface::*; 20 | 21 | #[derive(Default, Clone)] 22 | struct TimeSeriesItem { 23 | time: f32, 24 | sin: f32, 25 | cos: f32, 26 | } 27 | 28 | pub struct TimeSeries { 29 | emit: TimeSeriesEmitter, 30 | list: Vec, 31 | } 32 | 33 | impl TimeSeriesTrait for TimeSeries { 34 | fn new(emit: TimeSeriesEmitter, _: TimeSeriesList) -> TimeSeries { 35 | let mut series = TimeSeries { 36 | emit, 37 | list: Vec::new(), 38 | }; 39 | for i in 0..101 { 40 | let x = i as f32 / 10.; 41 | series.list.push(TimeSeriesItem { 42 | time: x, 43 | sin: x.sin(), 44 | cos: x.cos(), 45 | }); 46 | } 47 | series 48 | } 49 | fn emit(&mut self) -> &mut TimeSeriesEmitter { 50 | &mut self.emit 51 | } 52 | fn row_count(&self) -> usize { 53 | self.list.len() as usize 54 | } 55 | fn time(&self, row: usize) -> f32 { 56 | self.list[row as usize].time 57 | } 58 | fn set_time(&mut self, row: usize, v: f32) -> bool { 59 | self.list[row as usize].time = v; 60 | true 61 | } 62 | fn sin(&self, row: usize) -> f32 { 63 | self.list[row as usize].sin 64 | } 65 | fn set_sin(&mut self, row: usize, v: f32) -> bool { 66 | self.list[row as usize].sin = v; 67 | true 68 | } 69 | fn cos(&self, row: usize) -> f32 { 70 | self.list[row as usize].cos 71 | } 72 | fn set_cos(&mut self, row: usize, v: f32) -> bool { 73 | self.list[row as usize].cos = v; 74 | true 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /examples/todos/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project (my_rust_qt_quick_project) 2 | 3 | cmake_minimum_required(VERSION 3.10 FATAL_ERROR) 4 | cmake_policy(SET CMP0046 NEW) 5 | cmake_policy(SET CMP0063 NEW) 6 | cmake_policy(SET CMP0071 NEW) 7 | LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") 8 | 9 | string(TOUPPER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_UPPER) 10 | if(CMAKE_BUILD_TYPE_UPPER STREQUAL DEBUG) 11 | set(RUST_TARGET_DIR target/debug/) 12 | set(RUST_BUILD_FLAG) 13 | else() 14 | set(RUST_TARGET_DIR target/release/) 15 | set(RUST_BUILD_FLAG --release) 16 | endif() 17 | 18 | ### find dependencies ### 19 | 20 | include(FeatureSummary) 21 | find_package(Cargo REQUIRED) 22 | find_package(Rust REQUIRED) 23 | set(CMAKE_THREAD_PREFER_PTHREAD TRUE) 24 | find_package(Threads REQUIRED) 25 | 26 | set(QT_MIN_VERSION "5.6.0") 27 | find_package(Qt5 ${QT_MIN_VERSION} CONFIG 28 | REQUIRED COMPONENTS Core Quick 29 | ) 30 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 31 | set(CMAKE_AUTOMOC ON) 32 | set(CMAKE_AUTORCC ON) 33 | find_package(RustQtBindingGenerator REQUIRED) 34 | 35 | feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES) 36 | 37 | ### build commands ### 38 | 39 | SET(RUST_DIR "${CMAKE_CURRENT_SOURCE_DIR}/rust") 40 | if (MSVC) 41 | SET(RUST_LIB "${RUST_DIR}/${RUST_TARGET_DIR}/rust.lib") 42 | else() 43 | SET(RUST_LIB "${RUST_DIR}/${RUST_TARGET_DIR}/librust.a") 44 | endif() 45 | 46 | # generate c++ and rust code from bindings.json 47 | add_custom_command( 48 | OUTPUT "${RUST_DIR}/src/interface.rs" 49 | "${CMAKE_CURRENT_SOURCE_DIR}/src/Bindings.h" 50 | "${CMAKE_CURRENT_SOURCE_DIR}/src/Bindings.cpp" 51 | COMMAND "${RustQtBindingGenerator_EXECUTABLE}" #--overwrite-implementation 52 | "${CMAKE_CURRENT_SOURCE_DIR}/bindings.json" 53 | DEPENDS bindings.json 54 | ) 55 | 56 | # compile the rust code into a static library 57 | add_custom_command( 58 | OUTPUT "${RUST_LIB}" 59 | COMMAND ${Cargo_EXECUTABLE} build ${RUST_BUILD_FLAG} 60 | DEPENDS rust/src/lib.rs 61 | rust/src/implementation.rs 62 | rust/src/interface.rs 63 | WORKING_DIRECTORY "${RUST_DIR}" 64 | ) 65 | add_custom_target(rust_target DEPENDS "${RUST_LIB}") 66 | 67 | list(APPEND Libs "${RUST_LIB}") 68 | if (MSVC) 69 | list(APPEND Libs WS2_32.LIB Userenv.lib) 70 | endif() 71 | list(APPEND Libs Qt5::Core Qt5::Quick Threads::Threads ${CMAKE_DL_LIBS}) 72 | set(SRCS src/main.cpp src/Bindings.cpp "qml.qrc") 73 | add_executable(todos ${SRCS}) 74 | add_dependencies(todos rust_target) 75 | target_link_libraries(todos ${Libs}) 76 | set_target_properties(todos PROPERTIES 77 | CXX_STANDARD 11 78 | CXX_STANDARD_REQUIRED ON 79 | ) 80 | -------------------------------------------------------------------------------- /tests/test_functions.json: -------------------------------------------------------------------------------- 1 | { 2 | "cppFile": "test_functions_rust.cpp", 3 | "rust": { 4 | "dir": "rust_functions", 5 | "interfaceModule": "interface", 6 | "implementationModule": "implementation" 7 | }, 8 | "objects": { 9 | "Person": { 10 | "type": "Object", 11 | "properties": { 12 | "userName": { 13 | "type": "QString", 14 | "write": true 15 | } 16 | }, 17 | "functions": { 18 | "greet": { 19 | "return": "QString", 20 | "mut": false, 21 | "arguments": [ 22 | { 23 | "name": "name", 24 | "type": "QString" 25 | } 26 | ] 27 | }, 28 | "doubleName": { 29 | "return": "void", 30 | "mut": true, 31 | "arguments": [] 32 | }, 33 | "append": { 34 | "return": "void", 35 | "mut": true, 36 | "arguments": [ 37 | { 38 | "name": "suffix", 39 | "type": "QString" 40 | }, 41 | { 42 | "name": "amount", 43 | "type": "quint32" 44 | } 45 | ] 46 | }, 47 | "vowelsInName": { 48 | "return": "quint8", 49 | "arguments": [] 50 | }, 51 | "quote": { 52 | "return": "QString", 53 | "arguments": [ 54 | { 55 | "name": "prefix", 56 | "type": "QString" 57 | }, { 58 | "name": "suffix", 59 | "type": "QString" 60 | } 61 | ] 62 | }, 63 | "quoteBytes": { 64 | "return": "QByteArray", 65 | "arguments": [ 66 | { 67 | "name": "prefix", 68 | "type": "QByteArray" 69 | }, { 70 | "name": "suffix", 71 | "type": "QByteArray" 72 | } 73 | ] 74 | } 75 | } 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /tests/test_list_types.json: -------------------------------------------------------------------------------- 1 | { 2 | "cppFile": "test_list_types_rust.cpp", 3 | "rust": { 4 | "dir": "rust_list_types", 5 | "interfaceModule": "interface", 6 | "implementationModule": "implementation" 7 | }, 8 | "objects": { 9 | "List": { 10 | "type": "List", 11 | "itemProperties": { 12 | "boolean": { 13 | "type": "bool", 14 | "write": true 15 | }, 16 | "optionalBoolean": { 17 | "optional": true, 18 | "type": "bool", 19 | "write": true 20 | }, 21 | "i8": { 22 | "type": "qint8", 23 | "write": true 24 | }, 25 | "u8": { 26 | "type": "quint8", 27 | "write": true 28 | }, 29 | "i16": { 30 | "type": "qint16", 31 | "write": true 32 | }, 33 | "u16": { 34 | "type": "quint16", 35 | "write": true 36 | }, 37 | "i32": { 38 | "type": "qint32", 39 | "write": true 40 | }, 41 | "u32": { 42 | "type": "quint32", 43 | "write": true 44 | }, 45 | "i64": { 46 | "type": "qint64", 47 | "write": true 48 | }, 49 | "u64": { 50 | "type": "quint64", 51 | "write": true 52 | }, 53 | "f32": { 54 | "type": "float", 55 | "write": true 56 | }, 57 | "f64": { 58 | "type": "double", 59 | "write": true 60 | }, 61 | "string": { 62 | "type": "QString", 63 | "write": true, 64 | "roles": [ [ "display", "edit" ] ] 65 | }, 66 | "optionalString": { 67 | "type": "QString", 68 | "write": true, 69 | "optional": true 70 | }, 71 | "bytearray": { 72 | "type": "QByteArray", 73 | "write": true 74 | }, 75 | "optionalBytearray": { 76 | "type": "QByteArray", 77 | "write": true, 78 | "optional": true 79 | } 80 | } 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /demo/rust/src/implementation/demo.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Jos van den Oever 2 | // 3 | // This program is free software; you can redistribute it and/or 4 | // modify it under the terms of the GNU General Public License as 5 | // published by the Free Software Foundation; either version 2 of 6 | // the License or (at your option) version 3 or any later version 7 | // accepted by the membership of KDE e.V. (or its successor approved 8 | // by the membership of KDE e.V.), which shall act as a proxy 9 | // defined in Section 14 of version 3 of the license. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | use interface::*; 20 | use super::*; 21 | 22 | pub struct Demo { 23 | emit: DemoEmitter, 24 | fibonacci: Fibonacci, 25 | fibonacci_list: FibonacciList, 26 | file_system_tree: FileSystemTree, 27 | processes: Processes, 28 | time_series: TimeSeries 29 | } 30 | 31 | impl DemoTrait for Demo { 32 | fn new(emit: DemoEmitter, 33 | fibonacci: Fibonacci, 34 | fibonacci_list: FibonacciList, 35 | file_system_tree: FileSystemTree, 36 | processes: Processes, 37 | time_series: TimeSeries) -> Self { 38 | Demo { 39 | emit, 40 | fibonacci, 41 | fibonacci_list, 42 | file_system_tree, 43 | processes, 44 | time_series 45 | } 46 | } 47 | fn emit(&mut self) -> &mut DemoEmitter { 48 | &mut self.emit 49 | } 50 | fn fibonacci(&self) -> &Fibonacci { 51 | &self.fibonacci 52 | } 53 | fn fibonacci_mut(&mut self) -> &mut Fibonacci { 54 | &mut self.fibonacci 55 | } 56 | fn fibonacci_list(&self) -> &FibonacciList { 57 | &self.fibonacci_list 58 | } 59 | fn fibonacci_list_mut(&mut self) -> &mut FibonacciList { 60 | &mut self.fibonacci_list 61 | } 62 | fn file_system_tree(&self) -> &FileSystemTree { 63 | &self.file_system_tree 64 | } 65 | fn file_system_tree_mut(&mut self) -> &mut FileSystemTree { 66 | &mut self.file_system_tree 67 | } 68 | fn processes(&self) -> &Processes { 69 | &self.processes 70 | } 71 | fn processes_mut(&mut self) -> &mut Processes { 72 | &mut self.processes 73 | } 74 | fn time_series(&self) -> &TimeSeries { 75 | &self.time_series 76 | } 77 | fn time_series_mut(&mut self) -> &mut TimeSeries { 78 | &mut self.time_series 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /org.kde.rust_qt_binding_generator.desktop: -------------------------------------------------------------------------------- 1 | [Desktop Entry] 2 | Categories=Qt;KDE; 3 | Comment= 4 | Exec=rust_qt_binding_generatorelisa %U 5 | GenericName=Programming Binding Generator 6 | GenericName[ca]=Generador de vincles de programació 7 | GenericName[ca@valencia]=Generador de vincles de programació 8 | GenericName[de]=Generator für Programm-Bindungen 9 | GenericName[en_GB]=Programming Binding Generator 10 | GenericName[eo]=Programbindaĵa Generilo 11 | GenericName[es]=Generador de vínculos de programación 12 | GenericName[et]=Programmeerimise seoste generaator 13 | GenericName[eu]=Programatzeko lotura sortzailea 14 | GenericName[fr]=Générateur de liens de programmation 15 | GenericName[gl]=Xerador de API de programación 16 | GenericName[it]=Generatore di binding di programmazione 17 | GenericName[ka]=პროგრამირების მიბმების გენერატორი 18 | GenericName[ko]=프로그래밍 바인딩 생성기 19 | GenericName[nl]=Binding Generator voor programmeren 20 | GenericName[nn]=Generator for programmerings­bindingar 21 | GenericName[pl]=Tworzenie dowiązań programistycznych 22 | GenericName[pt]=Gerador de Interfaces de Programação 23 | GenericName[pt_BR]=Gerador de interfaces de programação 24 | GenericName[ru]=Создание привязок 25 | GenericName[sk]=Programovací generátor väzieb 26 | GenericName[sl]=Programming Binding Generator 27 | GenericName[sv]=Programmerar bindningsgenerator 28 | GenericName[tr]=Programlama Bağıntısı Oluşturucusu 29 | GenericName[uk]=Засіб створення програмних прив'язок 30 | GenericName[x-test]=xxProgramming Binding Generatorxx 31 | GenericName[zh_TW]=程式 Binding 產生器 32 | Icon=applications-development 33 | Name=Rust Qt Binding Generator 34 | Name[ca]=Generador de vincles per al Rust a les Qt 35 | Name[ca@valencia]=Generador de vincles per a Rust a les Qt 36 | Name[de]=Rust Qt Binding Generator 37 | Name[en_GB]=Rust Qt Binding Generator 38 | Name[eo]=Rust Qt-bindaĵa Generilo 39 | Name[es]=Generador de vínculos de Rust para Qt 40 | Name[et]=Rusti Qt seoste genereerija 41 | Name[eu]=«Rust» Qt lotura sortzailea 42 | Name[fr]=Générateur de liens « Rust » Qt 43 | Name[gl]=Xerador de API de Qt para Rust 44 | Name[it]=Generatore di binding Rust per Qt 45 | Name[ka]=Rust Qt მიბმის გენერატორი 46 | Name[ko]=Rust Qt 바인딩 생성기 47 | Name[nl]=Rust Qt Binding Generator 48 | Name[nn]=Generator for Rust–Qt-bindingar 49 | Name[pl]=Tworzenie powiązań Qt Rust 50 | Name[pt]=Gerador de Interfaces de Qt em Rust 51 | Name[pt_BR]=Gerador de interfaces Qt para Rust 52 | Name[ru]=Создание привязок Qt для Rust 53 | Name[sk]=Generátor väzieb Rust Qt 54 | Name[sl]=Rust Qt Binding Generator 55 | Name[sv]=Rust Qt-bindningsgenerator 56 | Name[tr]=Rust Qt Bağıntısı Oluşturucusu 57 | Name[uk]=Засіб створення прив'язок Qt до Rust 58 | Name[x-test]=xxRust Qt Binding Generatorxx 59 | Name[zh_TW]=Rust Qt Binding 產生器 60 | StartupNotify=false 61 | Terminal=true 62 | Type=Application 63 | MimeType=text/x-rust 64 | -------------------------------------------------------------------------------- /tests/test_objects.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Jos van den Oever 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License as 6 | * published by the Free Software Foundation; either version 2 of 7 | * the License or (at your option) version 3 or any later version 8 | * accepted by the membership of KDE e.V. (or its successor approved 9 | * by the membership of KDE e.V.), which shall act as a proxy 10 | * defined in Section 14 of version 3 of the license. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | #include "test_objects_rust.h" 22 | #include 23 | #include 24 | 25 | class TestRustObjects : public QObject 26 | { 27 | Q_OBJECT 28 | private slots: 29 | void testOneLevelConstructor(); 30 | void testOneLevelStringGetter(); 31 | void testOneLevelStringSetter(); 32 | void testTwoLevelsConstructor(); 33 | void testTwoLevelsStringGetter(); 34 | void testTwoLevelsStringSetter(); 35 | }; 36 | 37 | void TestRustObjects::testOneLevelConstructor() 38 | { 39 | Person person; 40 | } 41 | 42 | void TestRustObjects::testOneLevelStringGetter() 43 | { 44 | Person person; 45 | person.object()->setDescription("Konqi"); 46 | } 47 | 48 | void TestRustObjects::testOneLevelStringSetter() 49 | { 50 | // GIVEN 51 | Person person; 52 | QSignalSpy spy(person.object(), &InnerObject::descriptionChanged); 53 | 54 | // WHEN 55 | person.object()->setDescription("Konqi"); 56 | 57 | // THEN 58 | QVERIFY(spy.isValid()); 59 | QCOMPARE(spy.count(), 1); 60 | QCOMPARE(person.object()->description(), QString("Konqi")); 61 | } 62 | 63 | void TestRustObjects::testTwoLevelsConstructor() 64 | { 65 | Group group; 66 | } 67 | 68 | void TestRustObjects::testTwoLevelsStringGetter() 69 | { 70 | Group group; 71 | group.person()->object()->setDescription("Konqi"); 72 | } 73 | 74 | void TestRustObjects::testTwoLevelsStringSetter() 75 | { 76 | // GIVEN 77 | Group group; 78 | QSignalSpy spy(group.person()->object(), &InnerObject::descriptionChanged); 79 | 80 | // WHEN 81 | group.person()->object()->setDescription("Konqi"); 82 | 83 | // THEN 84 | QVERIFY(spy.isValid()); 85 | QCOMPARE(spy.count(), 1); 86 | QCOMPARE(group.person()->object()->description(), QString("Konqi")); 87 | } 88 | 89 | QTEST_MAIN(TestRustObjects) 90 | #include "test_objects.moc" 91 | -------------------------------------------------------------------------------- /examples/todos/src/Bindings.h: -------------------------------------------------------------------------------- 1 | /* generated by rust_qt_binding_generator */ 2 | #ifndef BINDINGS_H 3 | #define BINDINGS_H 4 | 5 | #include 6 | #include 7 | 8 | class Todos; 9 | 10 | class Todos : public QAbstractItemModel 11 | { 12 | Q_OBJECT 13 | public: 14 | class Private; 15 | private: 16 | Private * m_d; 17 | bool m_ownsPrivate; 18 | Q_PROPERTY(quint64 activeCount READ activeCount NOTIFY activeCountChanged FINAL) 19 | Q_PROPERTY(quint64 count READ count NOTIFY countChanged FINAL) 20 | explicit Todos(bool owned, QObject *parent); 21 | public: 22 | explicit Todos(QObject *parent = nullptr); 23 | ~Todos(); 24 | quint64 activeCount() const; 25 | quint64 count() const; 26 | Q_INVOKABLE void add(const QString& description); 27 | Q_INVOKABLE void clearCompleted(); 28 | Q_INVOKABLE bool remove(quint64 index); 29 | Q_INVOKABLE void setAll(bool completed); 30 | 31 | int columnCount(const QModelIndex &parent = QModelIndex()) const override; 32 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; 33 | QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override; 34 | QModelIndex parent(const QModelIndex &index) const override; 35 | bool hasChildren(const QModelIndex &parent = QModelIndex()) const override; 36 | int rowCount(const QModelIndex &parent = QModelIndex()) const override; 37 | bool canFetchMore(const QModelIndex &parent) const override; 38 | void fetchMore(const QModelIndex &parent) override; 39 | Qt::ItemFlags flags(const QModelIndex &index) const override; 40 | void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override; 41 | int role(const char* name) const; 42 | QHash roleNames() const override; 43 | QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; 44 | bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole) override; 45 | Q_INVOKABLE bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) override; 46 | Q_INVOKABLE bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override; 47 | bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override; 48 | Q_INVOKABLE bool completed(int row) const; 49 | Q_INVOKABLE bool setCompleted(int row, bool value); 50 | Q_INVOKABLE QString description(int row) const; 51 | Q_INVOKABLE bool setDescription(int row, const QString& value); 52 | 53 | Q_SIGNALS: 54 | // new data is ready to be made available to the model with fetchMore() 55 | void newDataReady(const QModelIndex &parent) const; 56 | private: 57 | QHash, QVariant> m_headerData; 58 | void initHeaderData(); 59 | void updatePersistentIndexes(); 60 | Q_SIGNALS: 61 | void activeCountChanged(); 62 | void countChanged(); 63 | }; 64 | #endif // BINDINGS_H 65 | -------------------------------------------------------------------------------- /tests/test_object_types.json: -------------------------------------------------------------------------------- 1 | { 2 | "cppFile": "test_object_types_rust.cpp", 3 | "rust": { 4 | "dir": "rust_object_types", 5 | "interfaceModule": "interface", 6 | "implementationModule": "implementation" 7 | }, 8 | "objects": { 9 | "Object": { 10 | "type": "Object", 11 | "properties": { 12 | "boolean": { 13 | "type": "bool", 14 | "write": true 15 | }, 16 | "optionalBoolean": { 17 | "optional": true, 18 | "type": "bool", 19 | "write": true 20 | }, 21 | "i8": { 22 | "type": "qint8", 23 | "write": true 24 | }, 25 | "u8": { 26 | "type": "quint8", 27 | "write": true 28 | }, 29 | "i16": { 30 | "type": "qint16", 31 | "write": true 32 | }, 33 | "u16": { 34 | "type": "quint16", 35 | "write": true 36 | }, 37 | "i32": { 38 | "type": "qint32", 39 | "write": true 40 | }, 41 | "u32": { 42 | "type": "quint32", 43 | "write": true 44 | }, 45 | "i64": { 46 | "type": "qint64", 47 | "write": true 48 | }, 49 | "u64": { 50 | "type": "quint64", 51 | "write": true 52 | }, 53 | "optionalU64": { 54 | "optional": true, 55 | "type": "quint64", 56 | "write": true 57 | }, 58 | "f32": { 59 | "type": "float", 60 | "write": true 61 | }, 62 | "f64": { 63 | "type": "double", 64 | "write": true 65 | }, 66 | "string": { 67 | "type": "QString", 68 | "write": true 69 | }, 70 | "optionalString": { 71 | "type": "QString", 72 | "write": true, 73 | "optional": true 74 | }, 75 | "bytearray": { 76 | "type": "QByteArray", 77 | "write": true 78 | }, 79 | "optionalBytearray": { 80 | "type": "QByteArray", 81 | "write": true, 82 | "optional": true 83 | }, 84 | "stringByFunction": { 85 | "type": "QString", 86 | "write": true, 87 | "rustByFunction": true 88 | } 89 | } 90 | } 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /tests/test_functions.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Jos van den Oever 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License as 6 | * published by the Free Software Foundation; either version 2 of 7 | * the License or (at your option) version 3 or any later version 8 | * accepted by the membership of KDE e.V. (or its successor approved 9 | * by the membership of KDE e.V.), which shall act as a proxy 10 | * defined in Section 14 of version 3 of the license. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | #include "test_functions_rust.h" 22 | #include 23 | #include 24 | 25 | class TestRustObject : public QObject 26 | { 27 | Q_OBJECT 28 | private slots: 29 | void testConstructor(); 30 | void testStringFunction(); 31 | void testSimpleFunction(); 32 | void testVoidFunction(); 33 | void testAppendFunction(); 34 | void testQuoteFunction(); 35 | void testQuoteBytesFunction(); 36 | }; 37 | 38 | void TestRustObject::testConstructor() 39 | { 40 | Person person; 41 | } 42 | 43 | void TestRustObject::testSimpleFunction() 44 | { 45 | // GIVEN 46 | Person person; 47 | person.setUserName("Konqi"); 48 | 49 | // THEN 50 | QCOMPARE(person.userName(), QString("Konqi")); 51 | QCOMPARE((int)person.vowelsInName(), 2); 52 | } 53 | 54 | void TestRustObject::testVoidFunction() 55 | { 56 | // GIVEN 57 | Person person; 58 | person.setUserName("Konqi"); 59 | 60 | // THEN 61 | person.doubleName(); 62 | QCOMPARE(person.userName(), QString("KonqiKonqi")); 63 | } 64 | 65 | void TestRustObject::testAppendFunction() 66 | { 67 | // GIVEN 68 | Person person; 69 | person.setUserName("Konqi"); 70 | 71 | // THEN 72 | person.append("!", 3); 73 | QCOMPARE(person.userName(), QString("Konqi!!!")); 74 | } 75 | 76 | void TestRustObject::testQuoteFunction() 77 | { 78 | // GIVEN 79 | Person person; 80 | person.setUserName("Konqi"); 81 | 82 | // THEN 83 | auto r = person.quote("<<", ">>"); 84 | QCOMPARE(r, QString("<>")); 85 | } 86 | 87 | void TestRustObject::testQuoteBytesFunction() 88 | { 89 | // GIVEN 90 | Person person; 91 | person.setUserName("Konqi"); 92 | 93 | // THEN 94 | auto r = person.quoteBytes("<<", ">>"); 95 | QCOMPARE(r, QByteArray("<>")); 96 | } 97 | 98 | void TestRustObject::testStringFunction() 99 | { 100 | // GIVEN 101 | Person person; 102 | person.setUserName("Konqi"); 103 | 104 | // THEN 105 | QCOMPARE(person.greet("John"), QString("Hello John, my name is Konqi, how is it going?")); 106 | } 107 | 108 | QTEST_MAIN(TestRustObject) 109 | #include "test_functions.moc" 110 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.10 FATAL_ERROR) 2 | 3 | project (rust_qt_binding_generator) 4 | 5 | set(QT_MIN_VERSION "5.6.0") 6 | set(KF5_MIN_VERSION "5.2.0") 7 | 8 | LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") 9 | find_package(ECM 1.0.0 NO_MODULE) 10 | if (ECM_FOUND) 11 | LIST(APPEND CMAKE_MODULE_PATH ${ECM_MODULE_PATH}) 12 | include(KDEInstallDirs) 13 | include(KDECMakeSettings) 14 | include(KDECompilerSettings NO_POLICY_SCOPE) 15 | include(ECMPoQmTools) 16 | else() 17 | cmake_policy(SET CMP0063 NEW) 18 | cmake_policy(SET CMP0071 NEW) 19 | enable_testing() 20 | set(CMAKE_AUTOMOC ON) 21 | endif() 22 | 23 | set(CMAKE_AUTOUIC ON) 24 | 25 | include(FeatureSummary) 26 | 27 | find_package(Cargo REQUIRED) 28 | find_package(Rust REQUIRED) 29 | set(CMAKE_THREAD_PREFER_PTHREAD TRUE) 30 | find_package(Threads REQUIRED) 31 | 32 | # Runtime information library -- dl on Debian, execinfo on FreeBSD. 33 | # This quiets a warning from rustc about linking to native artifacts. 34 | if (CMAKE_SYSTEM MATCHES "FreeBSD") 35 | set(NEED_DL_LIBRARY true) 36 | find_library(DL_LIBRARY execinfo) 37 | elseif (DEFINED CMAKE_DL_LIBS) 38 | set(NEED_DL_LIBRARY true) 39 | find_library(DL_LIBRARY ${CMAKE_DL_LIBS}) 40 | endif() 41 | 42 | # It would be neater to use set_package_properties() here and to 43 | # rely on feature_summary(), below, but that entails using find_package() 44 | # and moving this whole thing into a Find-module, which is over-wrought. 45 | if (NEED_DL_LIBRARY AND NOT DL_LIBRARY) 46 | message(FATAL_ERROR "No runtime information library (-ldl or -lexecinfo)") 47 | endif() 48 | 49 | # Find Qt modules 50 | find_package(Qt5 ${QT_MIN_VERSION} CONFIG 51 | REQUIRED COMPONENTS 52 | Core 53 | Test 54 | OPTIONAL_COMPONENTS 55 | Widgets 56 | Svg 57 | Quick 58 | ) 59 | find_package(Qt5QuickControls2 EXACT ${Qt5Core_VERSION}) 60 | find_package(Qt5Charts EXACT ${Qt5Core_VERSION}) 61 | 62 | find_package(KF5Kirigami2) 63 | 64 | feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES) 65 | 66 | string(TOUPPER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_UPPER) 67 | if(CMAKE_BUILD_TYPE_UPPER STREQUAL DEBUG) 68 | set(RUST_TARGET_DIR target/debug/) 69 | set(RUST_BUILD_FLAG) 70 | else() 71 | set(RUST_TARGET_DIR target/release/) 72 | set(RUST_BUILD_FLAG --release) 73 | endif() 74 | 75 | set(RustQtBindingGenerator_EXECUTABLE "${CMAKE_CURRENT_SOURCE_DIR}/${RUST_TARGET_DIR}rust_qt_binding_generator") 76 | add_custom_command( 77 | OUTPUT "${RustQtBindingGenerator_EXECUTABLE}" 78 | COMMAND ${Cargo_EXECUTABLE} build ${RUST_BUILD_FLAG} 79 | DEPENDS src/lib.rs 80 | src/configuration.rs 81 | src/cpp.rs 82 | src/rust.rs 83 | src/util.rs 84 | src/bin/rust_qt_binding_generator.rs 85 | WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" 86 | ) 87 | add_custom_target(rust_qt_binding_generator DEPENDS "${RustQtBindingGenerator_EXECUTABLE}") 88 | 89 | add_subdirectory(tests) 90 | 91 | if(Qt5Widgets_FOUND AND Qt5Svg_FOUND) 92 | add_subdirectory(demo) 93 | endif() 94 | 95 | if (ECM_FOUND) 96 | install(FILES org.kde.rust_qt_binding_generator.appdata.xml 97 | DESTINATION ${KDE_INSTALL_METAINFODIR}) 98 | endif() 99 | -------------------------------------------------------------------------------- /tests/test_list.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Jos van den Oever 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License as 6 | * published by the Free Software Foundation; either version 2 of 7 | * the License or (at your option) version 3 or any later version 8 | * accepted by the membership of KDE e.V. (or its successor approved 9 | * by the membership of KDE e.V.), which shall act as a proxy 10 | * defined in Section 14 of version 3 of the license. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | #include "test_list_rust.h" 22 | #include 23 | #include 24 | 25 | class TestRustList : public QObject 26 | { 27 | Q_OBJECT 28 | private slots: 29 | void testConstructor(); 30 | void testStringGetter(); 31 | void testStringSetter(); 32 | void testAccessByDefaultRole(); 33 | }; 34 | 35 | void TestRustList::testConstructor() 36 | { 37 | Persons persons; 38 | } 39 | 40 | void TestRustList::testStringGetter() 41 | { 42 | Persons persons; 43 | QCOMPARE(persons.rowCount(), 10); 44 | QVariant value = persons.data(persons.index(0,0)); 45 | // value should be empty string in default implementation 46 | QVERIFY(value.isValid()); 47 | QCOMPARE(value.type(), QVariant::String); 48 | QCOMPARE(value.toString(), QString()); 49 | } 50 | 51 | void TestRustList::testStringSetter() 52 | { 53 | // GIVEN 54 | Persons persons; 55 | QSignalSpy spy(&persons, &Persons::dataChanged); 56 | 57 | // WHEN 58 | const QModelIndex index(persons.index(0,0)); 59 | const bool set = persons.setData(index, "Konqi"); 60 | 61 | // THEN 62 | QCOMPARE(persons.columnCount(), 1); 63 | QVERIFY(set); 64 | QVERIFY(spy.isValid()); 65 | QCOMPARE(spy.count(), 1); 66 | QVariant value = persons.data(persons.index(0,0)); 67 | QCOMPARE(value.toString(), QString("Konqi")); 68 | } 69 | 70 | void TestRustList::testAccessByDefaultRole() 71 | { 72 | // GIVEN 73 | NoRole norole; 74 | QSignalSpy spy(&norole, &NoRole::dataChanged); 75 | auto ageRole = norole.role("userAge"); 76 | auto nameRole = norole.role("userName"); 77 | 78 | // WHEN 79 | const QModelIndex index(norole.index(0,0)); 80 | const bool setName = norole.setData(index, "Konqi", nameRole); 81 | const bool setAge = norole.setData(index, 21, ageRole); 82 | 83 | // THEN 84 | QCOMPARE(norole.columnCount(), 1); 85 | QVERIFY(setName); 86 | QVERIFY(setAge); 87 | QVERIFY(spy.isValid()); 88 | QCOMPARE(spy.count(), 2); 89 | QVariant name = norole.data(norole.index(0,0), nameRole); 90 | QCOMPARE(name.toString(), QString("Konqi")); 91 | QVariant age = norole.data(norole.index(0,0), ageRole); 92 | QCOMPARE(age.value(), (quint8)21); 93 | } 94 | 95 | QTEST_MAIN(TestRustList) 96 | #include "test_list.moc" 97 | -------------------------------------------------------------------------------- /demo/qml/ProcessesTree.qml: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Jos van den Oever 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License as 6 | * published by the Free Software Foundation; either version 2 of 7 | * the License or (at your option) version 3 or any later version 8 | * accepted by the membership of KDE e.V. (or its successor approved 9 | * by the membership of KDE e.V.), which shall act as a proxy 10 | * defined in Section 14 of version 3 of the license. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | import QtQuick 2.6 22 | import QtQml.Models 2.2 23 | import QtQuick.Controls 1.5 24 | import QtQuick.Layouts 1.3 25 | 26 | Item { 27 | TextField { 28 | id: processFilterInput 29 | focus: true 30 | width: parent.width 31 | placeholderText: "Filter processes" 32 | onTextChanged: { 33 | processes.filterRegExp = new RegExp(processFilterInput.text) 34 | } 35 | } 36 | TreeView { 37 | onClicked: { 38 | processSelection.select( 39 | index, ItemSelectionModel.ToggleCurrent) 40 | } 41 | Binding { 42 | target: demo.processes 43 | property: "active" 44 | value: visible 45 | } 46 | width: parent.width 47 | anchors.top: processFilterInput.bottom 48 | anchors.bottom: parent.bottom 49 | id: processView 50 | model: processes 51 | selection: processSelection 52 | selectionMode: SelectionMode.ExtendedSelection 53 | // selectionMode: SelectionMode.SingleSelection 54 | sortIndicatorVisible: true 55 | alternatingRowColors: true 56 | TableViewColumn { 57 | title: "name" 58 | role: "name" 59 | } 60 | TableViewColumn { 61 | title: "cpu" 62 | role: "cpuUsage" 63 | } 64 | TableViewColumn { 65 | title: "memory" 66 | role: "memory" 67 | } 68 | onSortIndicatorColumnChanged: sort() 69 | onSortIndicatorOrderChanged: sort() 70 | function sort() { 71 | var role = getColumn( 72 | processView.sortIndicatorColumn).role 73 | model.sortByRole(role, processView.sortIndicatorOrder) 74 | } 75 | Timer { 76 | interval: 100 77 | running: true 78 | repeat: true 79 | onTriggered: { 80 | var root = processView.rootIndex 81 | var systemd = processes.index(1, 0, root) 82 | if (processes.data(systemd) === "systemd") { 83 | processView.expand(systemd) 84 | running = false 85 | } 86 | } 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /tests/test_functions_rust.cpp: -------------------------------------------------------------------------------- 1 | /* generated by rust_qt_binding_generator */ 2 | #include "test_functions_rust.h" 3 | 4 | namespace { 5 | 6 | typedef void (*qstring_set)(QString* val, const char* utf8, int nbytes); 7 | void set_qstring(QString* val, const char* utf8, int nbytes) { 8 | *val = QString::fromUtf8(utf8, nbytes); 9 | } 10 | 11 | typedef void (*qbytearray_set)(QByteArray* val, const char* bytes, int nbytes); 12 | void set_qbytearray(QByteArray* v, const char* bytes, int nbytes) { 13 | if (v->isNull() && nbytes == 0) { 14 | *v = QByteArray(bytes, nbytes); 15 | } else { 16 | v->truncate(0); 17 | v->append(bytes, nbytes); 18 | } 19 | } 20 | inline void personUserNameChanged(Person* o) 21 | { 22 | Q_EMIT o->userNameChanged(); 23 | } 24 | } 25 | extern "C" { 26 | Person::Private* person_new(Person*, void (*)(Person*)); 27 | void person_free(Person::Private*); 28 | void person_user_name_get(const Person::Private*, QString*, qstring_set); 29 | void person_user_name_set(Person::Private*, const ushort *str, int len); 30 | void person_append(Person::Private*, const ushort*, int, quint32); 31 | void person_double_name(Person::Private*); 32 | void person_greet(const Person::Private*, const ushort*, int, QString*, qstring_set); 33 | void person_quote(const Person::Private*, const ushort*, int, const ushort*, int, QString*, qstring_set); 34 | void person_quote_bytes(const Person::Private*, const char*, int, const char*, int, QByteArray*, qbytearray_set); 35 | quint8 person_vowels_in_name(const Person::Private*); 36 | }; 37 | 38 | Person::Person(bool /*owned*/, QObject *parent): 39 | QObject(parent), 40 | m_d(nullptr), 41 | m_ownsPrivate(false) 42 | { 43 | } 44 | 45 | Person::Person(QObject *parent): 46 | QObject(parent), 47 | m_d(person_new(this, 48 | personUserNameChanged)), 49 | m_ownsPrivate(true) 50 | { 51 | } 52 | 53 | Person::~Person() { 54 | if (m_ownsPrivate) { 55 | person_free(m_d); 56 | } 57 | } 58 | QString Person::userName() const 59 | { 60 | QString v; 61 | person_user_name_get(m_d, &v, set_qstring); 62 | return v; 63 | } 64 | void Person::setUserName(const QString& v) { 65 | person_user_name_set(m_d, reinterpret_cast(v.data()), v.size()); 66 | } 67 | void Person::append(const QString& suffix, quint32 amount) 68 | { 69 | return person_append(m_d, suffix.utf16(), suffix.size(), amount); 70 | } 71 | void Person::doubleName() 72 | { 73 | return person_double_name(m_d); 74 | } 75 | QString Person::greet(const QString& name) const 76 | { 77 | QString s; 78 | person_greet(m_d, name.utf16(), name.size(), &s, set_qstring); 79 | return s; 80 | } 81 | QString Person::quote(const QString& prefix, const QString& suffix) const 82 | { 83 | QString s; 84 | person_quote(m_d, prefix.utf16(), prefix.size(), suffix.utf16(), suffix.size(), &s, set_qstring); 85 | return s; 86 | } 87 | QByteArray Person::quoteBytes(const QByteArray& prefix, const QByteArray& suffix) const 88 | { 89 | QByteArray s; 90 | person_quote_bytes(m_d, prefix.data(), prefix.size(), suffix.data(), suffix.size(), &s, set_qbytearray); 91 | return s; 92 | } 93 | quint8 Person::vowelsInName() const 94 | { 95 | return person_vowels_in_name(m_d); 96 | } 97 | -------------------------------------------------------------------------------- /demo/rust/src/implementation/fibonacci.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Jos van den Oever 2 | // 3 | // This program is free software; you can redistribute it and/or 4 | // modify it under the terms of the GNU General Public License as 5 | // published by the Free Software Foundation; either version 2 of 6 | // the License or (at your option) version 3 or any later version 7 | // accepted by the membership of KDE e.V. (or its successor approved 8 | // by the membership of KDE e.V.), which shall act as a proxy 9 | // defined in Section 14 of version 3 of the license. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | use std::thread; 20 | use interface::*; 21 | use std::sync::atomic::AtomicUsize; 22 | use std::sync::atomic::Ordering; 23 | use std::sync::Arc; 24 | 25 | fn fibonacci(input: u32) -> usize { 26 | if input <= 1 { 27 | return input as usize; 28 | } 29 | let mut i = 0; 30 | let mut sum = 0; 31 | let mut last = 0; 32 | let mut cur = 1; 33 | while i < input - 1 { 34 | sum = last + cur; 35 | last = cur; 36 | cur = sum; 37 | i += 1; 38 | } 39 | sum 40 | } 41 | 42 | pub struct Fibonacci { 43 | emit: FibonacciEmitter, 44 | input: u32, 45 | result: Arc, 46 | } 47 | 48 | impl FibonacciTrait for Fibonacci { 49 | fn new(emit: FibonacciEmitter) -> Fibonacci { 50 | Fibonacci { 51 | emit, 52 | input: 0, 53 | result: Arc::new(AtomicUsize::new(0)), 54 | } 55 | } 56 | fn emit(&mut self) -> &mut FibonacciEmitter { 57 | &mut self.emit 58 | } 59 | fn input(&self) -> u32 { 60 | self.input 61 | } 62 | fn set_input(&mut self, value: u32) { 63 | self.input = value; 64 | self.emit.input_changed(); 65 | let mut emit = self.emit.clone(); 66 | let result = self.result.clone(); 67 | result.swap(0, Ordering::SeqCst); 68 | emit.result_changed(); 69 | thread::spawn(move || { 70 | let r = fibonacci(value); 71 | result.swap(r, Ordering::SeqCst); 72 | emit.result_changed(); 73 | }); 74 | } 75 | fn result(&self) -> u64 { 76 | self.result.fetch_add(0, Ordering::SeqCst) as u64 77 | } 78 | } 79 | 80 | pub struct FibonacciList { 81 | emit: FibonacciListEmitter, 82 | } 83 | 84 | impl FibonacciListTrait for FibonacciList { 85 | fn new(emit: FibonacciListEmitter, _: FibonacciListList) -> FibonacciList { 86 | FibonacciList { 87 | emit, 88 | } 89 | } 90 | fn emit(&mut self) -> &mut FibonacciListEmitter { 91 | &mut self.emit 92 | } 93 | fn row_count(&self) -> usize { 94 | 93 95 | } 96 | fn row(&self, row: usize) -> u64 { 97 | row as u64 + 1 98 | } 99 | fn fibonacci_number(&self, row: usize) -> u64 { 100 | fibonacci(row as u32 + 1) as u64 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /docker/Dockerfile: -------------------------------------------------------------------------------- 1 | # Dockerfile for a development environment for rust_qt_binding_generator 2 | FROM ubuntu:18.04 3 | 4 | USER root 5 | 6 | RUN apt-get update && apt-get dist-upgrade -y 7 | 8 | # build dependencies and many extra qml modules 9 | RUN apt-get update && apt-get dist-upgrade -y && \ 10 | apt-get install -y --no-install-recommends \ 11 | ca-certificates \ 12 | qtcreator rustc cargo ninja-build make cmake g++ extra-cmake-modules \ 13 | kdesdk-scripts \ 14 | gdb valgrind git \ 15 | qtdeclarative5-dev-tools qtdeclarative5-dev qtquickcontrols2-5-dev \ 16 | libqt5charts5-dev libqt5svg5-dev qml-module-qtcharts \ 17 | qt5-doc qtbase5-doc qtcharts5-doc qtcreator-doc qtquickcontrols2-5-doc \ 18 | qtquickcontrols5-doc qtsvg5-doc qttools5-doc 19 | 20 | RUN apt-get update && apt-get dist-upgrade -y && \ 21 | apt-get install -y --no-install-recommends \ 22 | qtquickcontrols2-5-examples kirigami2-dev # qml-module-qt-labs-platform 23 | 24 | RUN apt-get update && apt-get dist-upgrade -y && \ 25 | apt-get install -y --no-install-recommends qt5-default 26 | 27 | # these are extra 28 | # RUN apt-get update && apt-get dist-upgrade -y && \ 29 | # apt-get install -y --no-install-recommends qbs-doc qml-module-org-kde-activities qml-module-org-kde-analitza qml-module-org-kde-bluezqt qml-module-org-kde-draganddrop qml-module-org-kde-extensionplugin qml-module-org-kde-games-core qml-module-org-kde-kaccounts qml-module-org-kde-kconfig qml-module-org-kde-kcoreaddons qml-module-org-kde-kholidays qml-module-org-kde-kio qml-module-org-kde-kirigami qml-module-org-kde-kirigami2 qml-module-org-kde-kquickcontrols qml-module-org-kde-kquickcontrolsaddons qml-module-org-kde-kwindowsystem qml-module-org-kde-newstuff qml-module-org-kde-people qml-module-org-kde-purpose qml-module-org-kde-runnermodel qml-module-org-kde-solid qml-module-org-kde-telepathy qml-module-qt-labs-calendar qml-module-qt-labs-folderlistmodel qml-module-qt-labs-platform qml-module-qt-labs-settings qml-module-qt-labs-sharedimage qml-module-qt-websockets qml-module-qt3d qml-module-qtaudioengine qml-module-qtbluetooth qml-module-qtfeedback qml-module-qtgraphicaleffects qml-module-qtgstreamer qml-module-qtlocation qml-module-qtmultimedia qml-module-qtnfc qml-module-qtpositioning qml-module-qtpurchasing qml-module-qtqml-models2 qml-module-qtqml-statemachine qml-module-qtquick-controls qml-module-qtquick-controls-styles-breeze qml-module-qtquick-controls2 qml-module-qtquick-dialogs qml-module-qtquick-extras qml-module-qtquick-layouts qml-module-qtquick-localstorage qml-module-qtquick-particles2 qml-module-qtquick-privatewidgets qml-module-qtquick-scene2d qml-module-qtquick-scene3d qml-module-qtquick-sharedimage qml-module-qtquick-templates2 qml-module-qtquick-virtualkeyboard qml-module-qtquick-window2 qml-module-qtquick-xmllistmodel qml-module-qtquick2 qml-module-qtsensors qml-module-qtsysteminfo qml-module-qttest qml-module-qtwayland-compositor qml-module-qtwebchannel qml-module-qtwebengine qml-module-qtwebkit qml-module-qtwebsockets qml-module-qtwebview qt-at-spi-doc qt3d5-doc qtconnectivity5-doc qtgraphicaleffects5-doc qtgstreamer-doc qtiplot-doc qtlocation5-doc qtmultimedia5-doc qtnetworkauth5-doc qtpim5-doc qtpositioning5-doc qtscript5-doc qtsensors5-doc qtserialport5-doc qtspeech5-doc qtwayland5-doc qtwebchannel-doc qtwebchannel5-doc qtwebengine5-doc qtwebkit5-doc qtwebkit5-examples-doc qtwebsockets5-doc qtwebview5-doc qtx11extras5-doc qtxmlpatterns5-doc 30 | 31 | RUN useradd neon 32 | 33 | USER neon 34 | 35 | WORKDIR /home/neon 36 | 37 | CMD ["/bin/bash", "-l"] 38 | -------------------------------------------------------------------------------- /templates/qt_quick/rust/src/interface.rs: -------------------------------------------------------------------------------- 1 | /* generated by rust_qt_binding_generator */ 2 | use libc::{c_char, c_ushort, c_int}; 3 | use std::slice; 4 | use std::char::decode_utf16; 5 | 6 | use std::sync::Arc; 7 | use std::sync::atomic::{AtomicPtr, Ordering}; 8 | use std::ptr::null; 9 | 10 | use implementation::*; 11 | 12 | 13 | pub enum QString {} 14 | 15 | fn set_string_from_utf16(s: &mut String, str: *const c_ushort, len: c_int) { 16 | let utf16 = unsafe { slice::from_raw_parts(str, to_usize(len)) }; 17 | let characters = decode_utf16(utf16.iter().cloned()) 18 | .map(|r| r.unwrap()); 19 | s.clear(); 20 | s.extend(characters); 21 | } 22 | 23 | 24 | 25 | fn to_usize(n: c_int) -> usize { 26 | if n < 0 { 27 | panic!("Cannot cast {} to usize", n); 28 | } 29 | n as usize 30 | } 31 | 32 | 33 | fn to_c_int(n: usize) -> c_int { 34 | if n > c_int::max_value() as usize { 35 | panic!("Cannot cast {} to c_int", n); 36 | } 37 | n as c_int 38 | } 39 | 40 | 41 | pub struct SimpleQObject {} 42 | 43 | pub struct SimpleEmitter { 44 | qobject: Arc>, 45 | message_changed: fn(*mut SimpleQObject), 46 | } 47 | 48 | unsafe impl Send for SimpleEmitter {} 49 | 50 | impl SimpleEmitter { 51 | /// Clone the emitter 52 | /// 53 | /// The emitter can only be cloned when it is mutable. The emitter calls 54 | /// into C++ code which may call into Rust again. If emmitting is possible 55 | /// from immutable structures, that might lead to access to a mutable 56 | /// reference. That is undefined behaviour and forbidden. 57 | pub fn clone(&mut self) -> SimpleEmitter { 58 | SimpleEmitter { 59 | qobject: self.qobject.clone(), 60 | message_changed: self.message_changed, 61 | } 62 | } 63 | fn clear(&self) { 64 | let n: *const SimpleQObject = null(); 65 | self.qobject.store(n as *mut SimpleQObject, Ordering::SeqCst); 66 | } 67 | pub fn message_changed(&mut self) { 68 | let ptr = self.qobject.load(Ordering::SeqCst); 69 | if !ptr.is_null() { 70 | (self.message_changed)(ptr); 71 | } 72 | } 73 | } 74 | 75 | pub trait SimpleTrait { 76 | fn new(emit: SimpleEmitter) -> Self; 77 | fn emit(&mut self) -> &mut SimpleEmitter; 78 | fn message(&self) -> &str; 79 | fn set_message(&mut self, value: String); 80 | } 81 | 82 | #[no_mangle] 83 | pub extern "C" fn simple_new( 84 | simple: *mut SimpleQObject, 85 | simple_message_changed: fn(*mut SimpleQObject), 86 | ) -> *mut Simple { 87 | let simple_emit = SimpleEmitter { 88 | qobject: Arc::new(AtomicPtr::new(simple)), 89 | message_changed: simple_message_changed, 90 | }; 91 | let d_simple = Simple::new(simple_emit); 92 | Box::into_raw(Box::new(d_simple)) 93 | } 94 | 95 | #[no_mangle] 96 | pub unsafe extern "C" fn simple_free(ptr: *mut Simple) { 97 | Box::from_raw(ptr).emit().clear(); 98 | } 99 | 100 | #[no_mangle] 101 | pub unsafe extern "C" fn simple_message_get( 102 | ptr: *const Simple, 103 | p: *mut QString, 104 | set: fn(*mut QString, *const c_char, c_int), 105 | ) { 106 | let o = &*ptr; 107 | let v = o.message(); 108 | let s: *const c_char = v.as_ptr() as *const c_char; 109 | set(p, s, to_c_int(v.len())); 110 | } 111 | 112 | #[no_mangle] 113 | pub unsafe extern "C" fn simple_message_set(ptr: *mut Simple, v: *const c_ushort, len: c_int) { 114 | let o = &mut *ptr; 115 | let mut s = String::new(); 116 | set_string_from_utf16(&mut s, v, len); 117 | o.set_message(s); 118 | } 119 | -------------------------------------------------------------------------------- /templates/qt_widgets/rust/src/interface.rs: -------------------------------------------------------------------------------- 1 | /* generated by rust_qt_binding_generator */ 2 | use libc::{c_char, c_ushort, c_int}; 3 | use std::slice; 4 | use std::char::decode_utf16; 5 | 6 | use std::sync::Arc; 7 | use std::sync::atomic::{AtomicPtr, Ordering}; 8 | use std::ptr::null; 9 | 10 | use implementation::*; 11 | 12 | 13 | pub enum QString {} 14 | 15 | fn set_string_from_utf16(s: &mut String, str: *const c_ushort, len: c_int) { 16 | let utf16 = unsafe { slice::from_raw_parts(str, to_usize(len)) }; 17 | let characters = decode_utf16(utf16.iter().cloned()) 18 | .map(|r| r.unwrap()); 19 | s.clear(); 20 | s.extend(characters); 21 | } 22 | 23 | 24 | 25 | fn to_usize(n: c_int) -> usize { 26 | if n < 0 { 27 | panic!("Cannot cast {} to usize", n); 28 | } 29 | n as usize 30 | } 31 | 32 | 33 | fn to_c_int(n: usize) -> c_int { 34 | if n > c_int::max_value() as usize { 35 | panic!("Cannot cast {} to c_int", n); 36 | } 37 | n as c_int 38 | } 39 | 40 | 41 | pub struct SimpleQObject {} 42 | 43 | pub struct SimpleEmitter { 44 | qobject: Arc>, 45 | message_changed: fn(*mut SimpleQObject), 46 | } 47 | 48 | unsafe impl Send for SimpleEmitter {} 49 | 50 | impl SimpleEmitter { 51 | /// Clone the emitter 52 | /// 53 | /// The emitter can only be cloned when it is mutable. The emitter calls 54 | /// into C++ code which may call into Rust again. If emmitting is possible 55 | /// from immutable structures, that might lead to access to a mutable 56 | /// reference. That is undefined behaviour and forbidden. 57 | pub fn clone(&mut self) -> SimpleEmitter { 58 | SimpleEmitter { 59 | qobject: self.qobject.clone(), 60 | message_changed: self.message_changed, 61 | } 62 | } 63 | fn clear(&self) { 64 | let n: *const SimpleQObject = null(); 65 | self.qobject.store(n as *mut SimpleQObject, Ordering::SeqCst); 66 | } 67 | pub fn message_changed(&mut self) { 68 | let ptr = self.qobject.load(Ordering::SeqCst); 69 | if !ptr.is_null() { 70 | (self.message_changed)(ptr); 71 | } 72 | } 73 | } 74 | 75 | pub trait SimpleTrait { 76 | fn new(emit: SimpleEmitter) -> Self; 77 | fn emit(&mut self) -> &mut SimpleEmitter; 78 | fn message(&self) -> &str; 79 | fn set_message(&mut self, value: String); 80 | } 81 | 82 | #[no_mangle] 83 | pub extern "C" fn simple_new( 84 | simple: *mut SimpleQObject, 85 | simple_message_changed: fn(*mut SimpleQObject), 86 | ) -> *mut Simple { 87 | let simple_emit = SimpleEmitter { 88 | qobject: Arc::new(AtomicPtr::new(simple)), 89 | message_changed: simple_message_changed, 90 | }; 91 | let d_simple = Simple::new(simple_emit); 92 | Box::into_raw(Box::new(d_simple)) 93 | } 94 | 95 | #[no_mangle] 96 | pub unsafe extern "C" fn simple_free(ptr: *mut Simple) { 97 | Box::from_raw(ptr).emit().clear(); 98 | } 99 | 100 | #[no_mangle] 101 | pub unsafe extern "C" fn simple_message_get( 102 | ptr: *const Simple, 103 | p: *mut QString, 104 | set: fn(*mut QString, *const c_char, c_int), 105 | ) { 106 | let o = &*ptr; 107 | let v = o.message(); 108 | let s: *const c_char = v.as_ptr() as *const c_char; 109 | set(p, s, to_c_int(v.len())); 110 | } 111 | 112 | #[no_mangle] 113 | pub unsafe extern "C" fn simple_message_set(ptr: *mut Simple, v: *const c_ushort, len: c_int) { 114 | let o = &mut *ptr; 115 | let mut s = String::new(); 116 | set_string_from_utf16(&mut s, v, len); 117 | o.set_message(s); 118 | } 119 | -------------------------------------------------------------------------------- /demo/qml/FileTreeView2.qml: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Jos van den Oever 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License as 6 | * published by the Free Software Foundation; either version 2 of 7 | * the License or (at your option) version 3 or any later version 8 | * accepted by the membership of KDE e.V. (or its successor approved 9 | * by the membership of KDE e.V.), which shall act as a proxy 10 | * defined in Section 14 of version 3 of the license. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | import QtQuick 2.6 22 | import QtQml.Models 2.2 23 | import QtQuick.Controls 2.2 24 | import QtQuick.Layouts 1.3 25 | 26 | ListView { 27 | id: view 28 | property string title 29 | header: Column { 30 | width: parent.width 31 | ToolBar { 32 | width: parent.width 33 | RowLayout { 34 | anchors.fill: parent 35 | ToolButton { 36 | text: qsTr("‹") 37 | enabled: dirModel.rootIndex.valid 38 | onClicked: { 39 | dirModel.rootIndex = dirModel.rootIndex.parent 40 | } 41 | } 42 | Label { 43 | text: view.title 44 | elide: Label.ElideMiddle 45 | horizontalAlignment: Qt.AlignHCenter 46 | verticalAlignment: Qt.AlignVCenter 47 | Layout.fillWidth: true 48 | } 49 | } 50 | } 51 | Row { 52 | Text { 53 | width: 200 54 | text: qsTr("Name") 55 | } 56 | Text { 57 | text: qsTr("Size") 58 | } 59 | } 60 | } 61 | model: DelegateModel { 62 | id: dirModel 63 | model: sortedFileSystem 64 | onRootIndexChanged: { 65 | var index = sortedFileSystem.mapToSource(rootIndex); 66 | view.title = demo.fileSystemTree.filePath(index) || ""; 67 | } 68 | delegate: Item { 69 | width: parent.width 70 | height: row.height 71 | Row { 72 | id: row 73 | Connections { 74 | target: sortedFileSystem 75 | onRowsInserted: { 76 | // enable the button if children were found when 'model' 77 | // was created or if they were just inserted 78 | button.enabled = model.hasModelChildren 79 | || dirModel.modelIndex(index) === parent 80 | } 81 | } 82 | Button { 83 | id: button 84 | width: 200 85 | text: fileName 86 | enabled: model.hasModelChildren 87 | onClicked: { 88 | view.model.rootIndex = view.model.modelIndex(index) 89 | } 90 | } 91 | Label { 92 | text: fileSize 93 | padding: button.padding 94 | } 95 | } 96 | } 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /tests/rust_object/src/interface.rs: -------------------------------------------------------------------------------- 1 | /* generated by rust_qt_binding_generator */ 2 | use libc::{c_char, c_ushort, c_int}; 3 | use std::slice; 4 | use std::char::decode_utf16; 5 | 6 | use std::sync::Arc; 7 | use std::sync::atomic::{AtomicPtr, Ordering}; 8 | use std::ptr::null; 9 | 10 | use implementation::*; 11 | 12 | 13 | pub enum QString {} 14 | 15 | fn set_string_from_utf16(s: &mut String, str: *const c_ushort, len: c_int) { 16 | let utf16 = unsafe { slice::from_raw_parts(str, to_usize(len)) }; 17 | let characters = decode_utf16(utf16.iter().cloned()) 18 | .map(|r| r.unwrap()); 19 | s.clear(); 20 | s.extend(characters); 21 | } 22 | 23 | 24 | 25 | fn to_usize(n: c_int) -> usize { 26 | if n < 0 { 27 | panic!("Cannot cast {} to usize", n); 28 | } 29 | n as usize 30 | } 31 | 32 | 33 | fn to_c_int(n: usize) -> c_int { 34 | if n > c_int::max_value() as usize { 35 | panic!("Cannot cast {} to c_int", n); 36 | } 37 | n as c_int 38 | } 39 | 40 | 41 | pub struct PersonQObject {} 42 | 43 | pub struct PersonEmitter { 44 | qobject: Arc>, 45 | user_name_changed: extern fn(*mut PersonQObject), 46 | } 47 | 48 | unsafe impl Send for PersonEmitter {} 49 | 50 | impl PersonEmitter { 51 | /// Clone the emitter 52 | /// 53 | /// The emitter can only be cloned when it is mutable. The emitter calls 54 | /// into C++ code which may call into Rust again. If emmitting is possible 55 | /// from immutable structures, that might lead to access to a mutable 56 | /// reference. That is undefined behaviour and forbidden. 57 | pub fn clone(&mut self) -> PersonEmitter { 58 | PersonEmitter { 59 | qobject: self.qobject.clone(), 60 | user_name_changed: self.user_name_changed, 61 | } 62 | } 63 | fn clear(&self) { 64 | let n: *const PersonQObject = null(); 65 | self.qobject.store(n as *mut PersonQObject, Ordering::SeqCst); 66 | } 67 | pub fn user_name_changed(&mut self) { 68 | let ptr = self.qobject.load(Ordering::SeqCst); 69 | if !ptr.is_null() { 70 | (self.user_name_changed)(ptr); 71 | } 72 | } 73 | } 74 | 75 | pub trait PersonTrait { 76 | fn new(emit: PersonEmitter) -> Self; 77 | fn emit(&mut self) -> &mut PersonEmitter; 78 | fn user_name(&self) -> &str; 79 | fn set_user_name(&mut self, value: String); 80 | } 81 | 82 | #[no_mangle] 83 | pub extern "C" fn person_new( 84 | person: *mut PersonQObject, 85 | person_user_name_changed: extern fn(*mut PersonQObject), 86 | ) -> *mut Person { 87 | let person_emit = PersonEmitter { 88 | qobject: Arc::new(AtomicPtr::new(person)), 89 | user_name_changed: person_user_name_changed, 90 | }; 91 | let d_person = Person::new(person_emit); 92 | Box::into_raw(Box::new(d_person)) 93 | } 94 | 95 | #[no_mangle] 96 | pub unsafe extern "C" fn person_free(ptr: *mut Person) { 97 | Box::from_raw(ptr).emit().clear(); 98 | } 99 | 100 | #[no_mangle] 101 | pub unsafe extern "C" fn person_user_name_get( 102 | ptr: *const Person, 103 | p: *mut QString, 104 | set: extern fn(*mut QString, *const c_char, c_int), 105 | ) { 106 | let o = &*ptr; 107 | let v = o.user_name(); 108 | let s: *const c_char = v.as_ptr() as *const c_char; 109 | set(p, s, to_c_int(v.len())); 110 | } 111 | 112 | #[no_mangle] 113 | pub unsafe extern "C" fn person_user_name_set(ptr: *mut Person, v: *const c_ushort, len: c_int) { 114 | let o = &mut *ptr; 115 | let mut s = String::new(); 116 | set_string_from_utf16(&mut s, v, len); 117 | o.set_user_name(s); 118 | } 119 | -------------------------------------------------------------------------------- /tests/test_objects_rust.cpp: -------------------------------------------------------------------------------- 1 | /* generated by rust_qt_binding_generator */ 2 | #include "test_objects_rust.h" 3 | 4 | namespace { 5 | 6 | typedef void (*qstring_set)(QString* val, const char* utf8, int nbytes); 7 | void set_qstring(QString* val, const char* utf8, int nbytes) { 8 | *val = QString::fromUtf8(utf8, nbytes); 9 | } 10 | inline void innerObjectDescriptionChanged(InnerObject* o) 11 | { 12 | Q_EMIT o->descriptionChanged(); 13 | } 14 | } 15 | extern "C" { 16 | Group::Private* group_new(Group*, Person*, InnerObject*, void (*)(InnerObject*)); 17 | void group_free(Group::Private*); 18 | Person::Private* group_person_get(const Group::Private*); 19 | }; 20 | 21 | extern "C" { 22 | InnerObject::Private* inner_object_new(InnerObject*, void (*)(InnerObject*)); 23 | void inner_object_free(InnerObject::Private*); 24 | void inner_object_description_get(const InnerObject::Private*, QString*, qstring_set); 25 | void inner_object_description_set(InnerObject::Private*, const ushort *str, int len); 26 | }; 27 | 28 | extern "C" { 29 | Person::Private* person_new(Person*, InnerObject*, void (*)(InnerObject*)); 30 | void person_free(Person::Private*); 31 | InnerObject::Private* person_object_get(const Person::Private*); 32 | }; 33 | 34 | Group::Group(bool /*owned*/, QObject *parent): 35 | QObject(parent), 36 | m_person(new Person(false, this)), 37 | m_d(nullptr), 38 | m_ownsPrivate(false) 39 | { 40 | } 41 | 42 | Group::Group(QObject *parent): 43 | QObject(parent), 44 | m_person(new Person(false, this)), 45 | m_d(group_new(this, m_person, m_person->m_object, 46 | innerObjectDescriptionChanged)), 47 | m_ownsPrivate(true) 48 | { 49 | m_person->m_d = group_person_get(m_d); 50 | m_person->m_object->m_d = person_object_get(m_person->m_d); 51 | } 52 | 53 | Group::~Group() { 54 | if (m_ownsPrivate) { 55 | group_free(m_d); 56 | } 57 | } 58 | const Person* Group::person() const 59 | { 60 | return m_person; 61 | } 62 | Person* Group::person() 63 | { 64 | return m_person; 65 | } 66 | InnerObject::InnerObject(bool /*owned*/, QObject *parent): 67 | QObject(parent), 68 | m_d(nullptr), 69 | m_ownsPrivate(false) 70 | { 71 | } 72 | 73 | InnerObject::InnerObject(QObject *parent): 74 | QObject(parent), 75 | m_d(inner_object_new(this, 76 | innerObjectDescriptionChanged)), 77 | m_ownsPrivate(true) 78 | { 79 | } 80 | 81 | InnerObject::~InnerObject() { 82 | if (m_ownsPrivate) { 83 | inner_object_free(m_d); 84 | } 85 | } 86 | QString InnerObject::description() const 87 | { 88 | QString v; 89 | inner_object_description_get(m_d, &v, set_qstring); 90 | return v; 91 | } 92 | void InnerObject::setDescription(const QString& v) { 93 | inner_object_description_set(m_d, reinterpret_cast(v.data()), v.size()); 94 | } 95 | Person::Person(bool /*owned*/, QObject *parent): 96 | QObject(parent), 97 | m_object(new InnerObject(false, this)), 98 | m_d(nullptr), 99 | m_ownsPrivate(false) 100 | { 101 | } 102 | 103 | Person::Person(QObject *parent): 104 | QObject(parent), 105 | m_object(new InnerObject(false, this)), 106 | m_d(person_new(this, m_object, 107 | innerObjectDescriptionChanged)), 108 | m_ownsPrivate(true) 109 | { 110 | m_object->m_d = person_object_get(m_d); 111 | } 112 | 113 | Person::~Person() { 114 | if (m_ownsPrivate) { 115 | person_free(m_d); 116 | } 117 | } 118 | const InnerObject* Person::object() const 119 | { 120 | return m_object; 121 | } 122 | InnerObject* Person::object() 123 | { 124 | return m_object; 125 | } 126 | -------------------------------------------------------------------------------- /demo/qml/FileTreeViewKirigami.qml: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Jos van den Oever 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License as 6 | * published by the Free Software Foundation; either version 2 of 7 | * the License or (at your option) version 3 or any later version 8 | * accepted by the membership of KDE e.V. (or its successor approved 9 | * by the membership of KDE e.V.), which shall act as a proxy 10 | * defined in Section 14 of version 3 of the license. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | import QtQuick 2.6 22 | import QtQml.Models 2.2 23 | import QtQuick.Controls 2.2 24 | import QtQuick.Layouts 1.3 25 | import org.kde.kirigami 2.0 as Kirigami 26 | 27 | ListView { 28 | id: view 29 | property string title 30 | header: Column { 31 | width: parent.width 32 | ToolBar { 33 | width: parent.width 34 | RowLayout { 35 | anchors.fill: parent 36 | ToolButton { 37 | text: qsTr("‹") 38 | enabled: dirModel.rootIndex.valid 39 | onClicked: { 40 | dirModel.rootIndex = dirModel.rootIndex.parent 41 | } 42 | } 43 | Kirigami.Heading { 44 | text: view.title 45 | elide: Label.ElideMiddle 46 | horizontalAlignment: Qt.AlignHCenter 47 | verticalAlignment: Qt.AlignVCenter 48 | Layout.fillWidth: true 49 | } 50 | } 51 | } 52 | Row { 53 | Text { 54 | width: 200 55 | text: qsTr("Name") 56 | } 57 | Text { 58 | text: qsTr("Size") 59 | } 60 | } 61 | } 62 | model: DelegateModel { 63 | id: dirModel 64 | model: sortedFileSystem 65 | onRootIndexChanged: { 66 | var index = sortedFileSystem.mapToSource(rootIndex); 67 | view.title = demo.fileSystemTree.filePath(index) || ""; 68 | } 69 | delegate: Item { 70 | width: parent.width 71 | height: row.height 72 | Row { 73 | id: row 74 | Connections { 75 | target: sortedFileSystem 76 | onRowsInserted: { 77 | // enable the button if children were found when 'model' 78 | // was created or if they were just inserted 79 | button.enabled = model.hasModelChildren 80 | || dirModel.modelIndex(index) === parent 81 | } 82 | } 83 | Button { 84 | id: button 85 | width: 200 86 | text: fileName 87 | enabled: model.hasModelChildren 88 | onClicked: { 89 | view.model.rootIndex = view.model.modelIndex(index) 90 | } 91 | } 92 | Label { 93 | text: fileSize 94 | padding: button.padding 95 | } 96 | } 97 | } 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /poqm/zh_TW/rqbgdemo_qt.po: -------------------------------------------------------------------------------- 1 | msgid "" 2 | msgstr "" 3 | "MIME-Version: 1.0\n" 4 | "Content-Type: text/plain; charset=UTF-8\n" 5 | "Content-Transfer-Encoding: 8bit\n" 6 | "X-Qt-Contexts: true\n" 7 | "Plural-Forms: nplurals=1; plural=0;\n" 8 | 9 | #: qml/chart.qml:36 10 | msgctxt "chart|" 11 | msgid "time [s]" 12 | msgstr "" 13 | 14 | #: qml/chart.qml:42 15 | msgctxt "chart|" 16 | msgid "electric potential [V]" 17 | msgstr "" 18 | 19 | #: qml/DataAndChart.qml:85 20 | msgctxt "DataAndChart|" 21 | msgid "time" 22 | msgstr "" 23 | 24 | #: qml/DataAndChart.qml:89 25 | msgctxt "DataAndChart|" 26 | msgid "sin" 27 | msgstr "" 28 | 29 | #: qml/DataAndChart.qml:93 30 | msgctxt "DataAndChart|" 31 | msgid "cos" 32 | msgstr "" 33 | 34 | #: qml/DataAndChart.qml:104 35 | msgctxt "DataAndChart|" 36 | msgid "QtChart is not available." 37 | msgstr "" 38 | 39 | #: qml/Fibonacci.qml:28 40 | msgctxt "Fibonacci|" 41 | msgid "Calculate the nth Fibonacci number" 42 | msgstr "" 43 | 44 | #: qml/Fibonacci.qml:32 45 | msgctxt "Fibonacci|" 46 | msgid "Your number" 47 | msgstr "" 48 | 49 | #: qml/Fibonacci.qml:46 50 | msgctxt "Fibonacci|" 51 | msgid "The Fibonacci number: " 52 | msgstr "" 53 | 54 | #: qml/Fibonacci2.qml:27 55 | msgctxt "Fibonacci2|" 56 | msgid "Calculate the nth Fibonacci number" 57 | msgstr "" 58 | 59 | #: qml/Fibonacci2.qml:31 60 | msgctxt "Fibonacci2|" 61 | msgid "Your number" 62 | msgstr "" 63 | 64 | #: qml/Fibonacci2.qml:45 65 | msgctxt "Fibonacci2|" 66 | msgid "The Fibonacci number: " 67 | msgstr "" 68 | 69 | #: qml/FibonacciList.qml:30 70 | msgctxt "FibonacciList|" 71 | msgid "Row" 72 | msgstr "" 73 | 74 | #: qml/FibonacciList.qml:35 75 | msgctxt "FibonacciList|" 76 | msgid "Fibonacci number" 77 | msgstr "" 78 | 79 | #: qml/FibonacciList2.qml:29 80 | msgctxt "FibonacciList2|" 81 | msgid "Row" 82 | msgstr "" 83 | 84 | #: qml/FibonacciList2.qml:32 85 | msgctxt "FibonacciList2|" 86 | msgid "Fibonacci number" 87 | msgstr "" 88 | 89 | #: qml/FibonacciListKirigami.qml:29 90 | msgctxt "FibonacciListKirigami|" 91 | msgid "Row" 92 | msgstr "" 93 | 94 | #: qml/FibonacciListKirigami.qml:29 95 | msgctxt "FibonacciListKirigami|" 96 | msgid "Fibonacci number" 97 | msgstr "" 98 | 99 | #: qml/FileTreeView2.qml:36 100 | msgctxt "FileTreeView2|" 101 | msgid "‹" 102 | msgstr "" 103 | 104 | #: qml/FileTreeView2.qml:54 105 | msgctxt "FileTreeView2|" 106 | msgid "Name" 107 | msgstr "" 108 | 109 | #: qml/FileTreeView2.qml:57 110 | msgctxt "FileTreeView2|" 111 | msgid "Size" 112 | msgstr "" 113 | 114 | #: qml/FileTreeViewKirigami.qml:37 115 | msgctxt "FileTreeViewKirigami|" 116 | msgid "‹" 117 | msgstr "" 118 | 119 | #: qml/FileTreeViewKirigami.qml:55 120 | msgctxt "FileTreeViewKirigami|" 121 | msgid "Name" 122 | msgstr "" 123 | 124 | #: qml/FileTreeViewKirigami.qml:58 125 | msgctxt "FileTreeViewKirigami|" 126 | msgid "Size" 127 | msgstr "" 128 | 129 | #: src/main.cpp:240 130 | msgctxt "main|" 131 | msgid "Calculate the nth Fibonacci number" 132 | msgstr "" 133 | 134 | #: src/main.cpp:257 135 | msgctxt "main|" 136 | msgid "The Fibonacci number: " 137 | msgstr "" 138 | 139 | #: src/main.cpp:273 140 | msgctxt "main|" 141 | msgid "Row" 142 | msgstr "" 143 | 144 | #: src/main.cpp:275 145 | msgctxt "main|" 146 | msgid "Fibonacci number" 147 | msgstr "" 148 | 149 | #: src/main.cpp:284 150 | msgctxt "main|" 151 | msgid "Name" 152 | msgstr "" 153 | 154 | #: src/main.cpp:286 155 | msgctxt "main|" 156 | msgid "Size" 157 | msgstr "" 158 | 159 | #: src/main.cpp:422 160 | msgctxt "main|" 161 | msgid "Initial widget style." 162 | msgstr "" 163 | 164 | #: src/main.cpp:423 165 | msgctxt "main|" 166 | msgid "style" 167 | msgstr "" 168 | 169 | #: src/main.cpp:428 170 | msgctxt "main|" 171 | msgid "Initial tab." 172 | msgstr "" 173 | 174 | #: src/main.cpp:429 175 | msgctxt "main|" 176 | msgid "tab" 177 | msgstr "" 178 | -------------------------------------------------------------------------------- /tests/test_object_types_rust.h: -------------------------------------------------------------------------------- 1 | /* generated by rust_qt_binding_generator */ 2 | #ifndef TEST_OBJECT_TYPES_RUST_H 3 | #define TEST_OBJECT_TYPES_RUST_H 4 | 5 | #include 6 | #include 7 | 8 | class Object; 9 | 10 | class Object : public QObject 11 | { 12 | Q_OBJECT 13 | public: 14 | class Private; 15 | private: 16 | Private * m_d; 17 | bool m_ownsPrivate; 18 | Q_PROPERTY(bool boolean READ boolean WRITE setBoolean NOTIFY booleanChanged FINAL) 19 | Q_PROPERTY(QByteArray bytearray READ bytearray WRITE setBytearray NOTIFY bytearrayChanged FINAL) 20 | Q_PROPERTY(float f32 READ f32 WRITE setF32 NOTIFY f32Changed FINAL) 21 | Q_PROPERTY(double f64 READ f64 WRITE setF64 NOTIFY f64Changed FINAL) 22 | Q_PROPERTY(qint16 i16 READ i16 WRITE setI16 NOTIFY i16Changed FINAL) 23 | Q_PROPERTY(qint32 i32 READ i32 WRITE setI32 NOTIFY i32Changed FINAL) 24 | Q_PROPERTY(qint64 i64 READ i64 WRITE setI64 NOTIFY i64Changed FINAL) 25 | Q_PROPERTY(qint8 i8 READ i8 WRITE setI8 NOTIFY i8Changed FINAL) 26 | Q_PROPERTY(QVariant optionalBoolean READ optionalBoolean WRITE setOptionalBoolean NOTIFY optionalBooleanChanged FINAL) 27 | Q_PROPERTY(QByteArray optionalBytearray READ optionalBytearray WRITE setOptionalBytearray NOTIFY optionalBytearrayChanged FINAL) 28 | Q_PROPERTY(QString optionalString READ optionalString WRITE setOptionalString NOTIFY optionalStringChanged FINAL) 29 | Q_PROPERTY(QVariant optionalU64 READ optionalU64 WRITE setOptionalU64 NOTIFY optionalU64Changed FINAL) 30 | Q_PROPERTY(QString string READ string WRITE setString NOTIFY stringChanged FINAL) 31 | Q_PROPERTY(QString stringByFunction READ stringByFunction WRITE setStringByFunction NOTIFY stringByFunctionChanged FINAL) 32 | Q_PROPERTY(quint16 u16 READ u16 WRITE setU16 NOTIFY u16Changed FINAL) 33 | Q_PROPERTY(quint32 u32 READ u32 WRITE setU32 NOTIFY u32Changed FINAL) 34 | Q_PROPERTY(quint64 u64 READ u64 WRITE setU64 NOTIFY u64Changed FINAL) 35 | Q_PROPERTY(quint8 u8 READ u8 WRITE setU8 NOTIFY u8Changed FINAL) 36 | explicit Object(bool owned, QObject *parent); 37 | public: 38 | explicit Object(QObject *parent = nullptr); 39 | ~Object(); 40 | bool boolean() const; 41 | void setBoolean(bool v); 42 | QByteArray bytearray() const; 43 | void setBytearray(const QByteArray& v); 44 | float f32() const; 45 | void setF32(float v); 46 | double f64() const; 47 | void setF64(double v); 48 | qint16 i16() const; 49 | void setI16(qint16 v); 50 | qint32 i32() const; 51 | void setI32(qint32 v); 52 | qint64 i64() const; 53 | void setI64(qint64 v); 54 | qint8 i8() const; 55 | void setI8(qint8 v); 56 | QVariant optionalBoolean() const; 57 | void setOptionalBoolean(const QVariant& v); 58 | QByteArray optionalBytearray() const; 59 | void setOptionalBytearray(const QByteArray& v); 60 | QString optionalString() const; 61 | void setOptionalString(const QString& v); 62 | QVariant optionalU64() const; 63 | void setOptionalU64(const QVariant& v); 64 | QString string() const; 65 | void setString(const QString& v); 66 | QString stringByFunction() const; 67 | void setStringByFunction(const QString& v); 68 | quint16 u16() const; 69 | void setU16(quint16 v); 70 | quint32 u32() const; 71 | void setU32(quint32 v); 72 | quint64 u64() const; 73 | void setU64(quint64 v); 74 | quint8 u8() const; 75 | void setU8(quint8 v); 76 | Q_SIGNALS: 77 | void booleanChanged(); 78 | void bytearrayChanged(); 79 | void f32Changed(); 80 | void f64Changed(); 81 | void i16Changed(); 82 | void i32Changed(); 83 | void i64Changed(); 84 | void i8Changed(); 85 | void optionalBooleanChanged(); 86 | void optionalBytearrayChanged(); 87 | void optionalStringChanged(); 88 | void optionalU64Changed(); 89 | void stringChanged(); 90 | void stringByFunctionChanged(); 91 | void u16Changed(); 92 | void u32Changed(); 93 | void u64Changed(); 94 | void u8Changed(); 95 | }; 96 | #endif // TEST_OBJECT_TYPES_RUST_H 97 | -------------------------------------------------------------------------------- /poqm/lt/rqbgdemo_qt.po: -------------------------------------------------------------------------------- 1 | msgid "" 2 | msgstr "" 3 | "Project-Id-Version: trunk-kf 5\n" 4 | "Last-Translator: Automatically generated\n" 5 | "Language-Team: lt\n" 6 | "Language: lt\n" 7 | "MIME-Version: 1.0\n" 8 | "Content-Type: text/plain; charset=UTF-8\n" 9 | "Content-Transfer-Encoding: 8bit\n" 10 | "X-Qt-Contexts: true\n" 11 | "Plural-Forms: nplurals=4; plural=(n==1 ? 0 : n%10>=2 && (n%100<10 || n" 12 | "%100>=20) ? 1 : n%10==0 || (n%100>10 && n%100<20) ? 2 : 3);\n" 13 | 14 | #: qml/chart.qml:36 15 | msgctxt "chart|" 16 | msgid "time [s]" 17 | msgstr "" 18 | 19 | #: qml/chart.qml:42 20 | msgctxt "chart|" 21 | msgid "electric potential [V]" 22 | msgstr "" 23 | 24 | #: qml/DataAndChart.qml:85 25 | msgctxt "DataAndChart|" 26 | msgid "time" 27 | msgstr "" 28 | 29 | #: qml/DataAndChart.qml:89 30 | msgctxt "DataAndChart|" 31 | msgid "sin" 32 | msgstr "" 33 | 34 | #: qml/DataAndChart.qml:93 35 | msgctxt "DataAndChart|" 36 | msgid "cos" 37 | msgstr "" 38 | 39 | #: qml/DataAndChart.qml:104 40 | msgctxt "DataAndChart|" 41 | msgid "QtChart is not available." 42 | msgstr "" 43 | 44 | #: qml/Fibonacci.qml:28 45 | msgctxt "Fibonacci|" 46 | msgid "Calculate the nth Fibonacci number" 47 | msgstr "" 48 | 49 | #: qml/Fibonacci.qml:32 50 | msgctxt "Fibonacci|" 51 | msgid "Your number" 52 | msgstr "" 53 | 54 | #: qml/Fibonacci.qml:46 55 | msgctxt "Fibonacci|" 56 | msgid "The Fibonacci number: " 57 | msgstr "" 58 | 59 | #: qml/Fibonacci2.qml:27 60 | msgctxt "Fibonacci2|" 61 | msgid "Calculate the nth Fibonacci number" 62 | msgstr "" 63 | 64 | #: qml/Fibonacci2.qml:31 65 | msgctxt "Fibonacci2|" 66 | msgid "Your number" 67 | msgstr "" 68 | 69 | #: qml/Fibonacci2.qml:45 70 | msgctxt "Fibonacci2|" 71 | msgid "The Fibonacci number: " 72 | msgstr "" 73 | 74 | #: qml/FibonacciList.qml:30 75 | msgctxt "FibonacciList|" 76 | msgid "Row" 77 | msgstr "" 78 | 79 | #: qml/FibonacciList.qml:35 80 | msgctxt "FibonacciList|" 81 | msgid "Fibonacci number" 82 | msgstr "" 83 | 84 | #: qml/FibonacciList2.qml:29 85 | msgctxt "FibonacciList2|" 86 | msgid "Row" 87 | msgstr "" 88 | 89 | #: qml/FibonacciList2.qml:32 90 | msgctxt "FibonacciList2|" 91 | msgid "Fibonacci number" 92 | msgstr "" 93 | 94 | #: qml/FibonacciListKirigami.qml:29 95 | msgctxt "FibonacciListKirigami|" 96 | msgid "Row" 97 | msgstr "" 98 | 99 | #: qml/FibonacciListKirigami.qml:29 100 | msgctxt "FibonacciListKirigami|" 101 | msgid "Fibonacci number" 102 | msgstr "" 103 | 104 | #: qml/FileTreeView2.qml:36 105 | msgctxt "FileTreeView2|" 106 | msgid "‹" 107 | msgstr "" 108 | 109 | #: qml/FileTreeView2.qml:54 110 | msgctxt "FileTreeView2|" 111 | msgid "Name" 112 | msgstr "" 113 | 114 | #: qml/FileTreeView2.qml:57 115 | msgctxt "FileTreeView2|" 116 | msgid "Size" 117 | msgstr "" 118 | 119 | #: qml/FileTreeViewKirigami.qml:37 120 | msgctxt "FileTreeViewKirigami|" 121 | msgid "‹" 122 | msgstr "" 123 | 124 | #: qml/FileTreeViewKirigami.qml:55 125 | msgctxt "FileTreeViewKirigami|" 126 | msgid "Name" 127 | msgstr "" 128 | 129 | #: qml/FileTreeViewKirigami.qml:58 130 | msgctxt "FileTreeViewKirigami|" 131 | msgid "Size" 132 | msgstr "" 133 | 134 | #: src/main.cpp:240 135 | msgctxt "main|" 136 | msgid "Calculate the nth Fibonacci number" 137 | msgstr "" 138 | 139 | #: src/main.cpp:257 140 | msgctxt "main|" 141 | msgid "The Fibonacci number: " 142 | msgstr "" 143 | 144 | #: src/main.cpp:273 145 | msgctxt "main|" 146 | msgid "Row" 147 | msgstr "" 148 | 149 | #: src/main.cpp:275 150 | msgctxt "main|" 151 | msgid "Fibonacci number" 152 | msgstr "" 153 | 154 | #: src/main.cpp:284 155 | msgctxt "main|" 156 | msgid "Name" 157 | msgstr "" 158 | 159 | #: src/main.cpp:286 160 | msgctxt "main|" 161 | msgid "Size" 162 | msgstr "" 163 | 164 | #: src/main.cpp:422 165 | msgctxt "main|" 166 | msgid "Initial widget style." 167 | msgstr "" 168 | 169 | #: src/main.cpp:423 170 | msgctxt "main|" 171 | msgid "style" 172 | msgstr "" 173 | 174 | #: src/main.cpp:428 175 | msgctxt "main|" 176 | msgid "Initial tab." 177 | msgstr "" 178 | 179 | #: src/main.cpp:429 180 | msgctxt "main|" 181 | msgid "tab" 182 | msgstr "" 183 | -------------------------------------------------------------------------------- /tests/test_list_types_rust.h: -------------------------------------------------------------------------------- 1 | /* generated by rust_qt_binding_generator */ 2 | #ifndef TEST_LIST_TYPES_RUST_H 3 | #define TEST_LIST_TYPES_RUST_H 4 | 5 | #include 6 | #include 7 | 8 | class List; 9 | 10 | class List : public QAbstractItemModel 11 | { 12 | Q_OBJECT 13 | public: 14 | class Private; 15 | private: 16 | Private * m_d; 17 | bool m_ownsPrivate; 18 | explicit List(bool owned, QObject *parent); 19 | public: 20 | explicit List(QObject *parent = nullptr); 21 | ~List(); 22 | 23 | int columnCount(const QModelIndex &parent = QModelIndex()) const override; 24 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; 25 | QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override; 26 | QModelIndex parent(const QModelIndex &index) const override; 27 | bool hasChildren(const QModelIndex &parent = QModelIndex()) const override; 28 | int rowCount(const QModelIndex &parent = QModelIndex()) const override; 29 | bool canFetchMore(const QModelIndex &parent) const override; 30 | void fetchMore(const QModelIndex &parent) override; 31 | Qt::ItemFlags flags(const QModelIndex &index) const override; 32 | void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override; 33 | int role(const char* name) const; 34 | QHash roleNames() const override; 35 | QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; 36 | bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole) override; 37 | Q_INVOKABLE bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) override; 38 | Q_INVOKABLE bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override; 39 | bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override; 40 | Q_INVOKABLE bool boolean(int row) const; 41 | Q_INVOKABLE bool setBoolean(int row, bool value); 42 | Q_INVOKABLE QByteArray bytearray(int row) const; 43 | Q_INVOKABLE bool setBytearray(int row, const QByteArray& value); 44 | Q_INVOKABLE float f32(int row) const; 45 | Q_INVOKABLE bool setF32(int row, float value); 46 | Q_INVOKABLE double f64(int row) const; 47 | Q_INVOKABLE bool setF64(int row, double value); 48 | Q_INVOKABLE qint16 i16(int row) const; 49 | Q_INVOKABLE bool setI16(int row, qint16 value); 50 | Q_INVOKABLE qint32 i32(int row) const; 51 | Q_INVOKABLE bool setI32(int row, qint32 value); 52 | Q_INVOKABLE qint64 i64(int row) const; 53 | Q_INVOKABLE bool setI64(int row, qint64 value); 54 | Q_INVOKABLE qint8 i8(int row) const; 55 | Q_INVOKABLE bool setI8(int row, qint8 value); 56 | Q_INVOKABLE QVariant optionalBoolean(int row) const; 57 | Q_INVOKABLE bool setOptionalBoolean(int row, const QVariant& value); 58 | Q_INVOKABLE QByteArray optionalBytearray(int row) const; 59 | Q_INVOKABLE bool setOptionalBytearray(int row, const QByteArray& value); 60 | Q_INVOKABLE QString optionalString(int row) const; 61 | Q_INVOKABLE bool setOptionalString(int row, const QString& value); 62 | Q_INVOKABLE QString string(int row) const; 63 | Q_INVOKABLE bool setString(int row, const QString& value); 64 | Q_INVOKABLE quint16 u16(int row) const; 65 | Q_INVOKABLE bool setU16(int row, quint16 value); 66 | Q_INVOKABLE quint32 u32(int row) const; 67 | Q_INVOKABLE bool setU32(int row, quint32 value); 68 | Q_INVOKABLE quint64 u64(int row) const; 69 | Q_INVOKABLE bool setU64(int row, quint64 value); 70 | Q_INVOKABLE quint8 u8(int row) const; 71 | Q_INVOKABLE bool setU8(int row, quint8 value); 72 | 73 | Q_SIGNALS: 74 | // new data is ready to be made available to the model with fetchMore() 75 | void newDataReady(const QModelIndex &parent) const; 76 | private: 77 | QHash, QVariant> m_headerData; 78 | void initHeaderData(); 79 | void updatePersistentIndexes(); 80 | Q_SIGNALS: 81 | }; 82 | #endif // TEST_LIST_TYPES_RUST_H 83 | -------------------------------------------------------------------------------- /poqm/ja/rqbgdemo_qt.po: -------------------------------------------------------------------------------- 1 | msgid "" 2 | msgstr "" 3 | "Project-Id-Version: Demo_qt\n" 4 | "PO-Revision-Date: 2023-05-28 23:14-0700\n" 5 | "Last-Translator: Fumiaki Okushi \n" 6 | "Language-Team: Japanese \n" 7 | "Language: ja\n" 8 | "MIME-Version: 1.0\n" 9 | "Content-Type: text/plain; charset=UTF-8\n" 10 | "Content-Transfer-Encoding: 8bit\n" 11 | "Plural-Forms: nplurals=1; plural=0;\n" 12 | "X-Accelerator-Marker: &\n" 13 | "X-Text-Markup: qtrich\n" 14 | "X-Qt-Contexts: true\n" 15 | 16 | #: qml/chart.qml:36 17 | msgctxt "chart|" 18 | msgid "time [s]" 19 | msgstr "" 20 | 21 | #: qml/chart.qml:42 22 | msgctxt "chart|" 23 | msgid "electric potential [V]" 24 | msgstr "" 25 | 26 | #: qml/DataAndChart.qml:85 27 | msgctxt "DataAndChart|" 28 | msgid "time" 29 | msgstr "" 30 | 31 | #: qml/DataAndChart.qml:89 32 | msgctxt "DataAndChart|" 33 | msgid "sin" 34 | msgstr "" 35 | 36 | #: qml/DataAndChart.qml:93 37 | msgctxt "DataAndChart|" 38 | msgid "cos" 39 | msgstr "" 40 | 41 | #: qml/DataAndChart.qml:104 42 | msgctxt "DataAndChart|" 43 | msgid "QtChart is not available." 44 | msgstr "" 45 | 46 | #: qml/Fibonacci.qml:28 47 | msgctxt "Fibonacci|" 48 | msgid "Calculate the nth Fibonacci number" 49 | msgstr "" 50 | 51 | #: qml/Fibonacci.qml:32 52 | msgctxt "Fibonacci|" 53 | msgid "Your number" 54 | msgstr "" 55 | 56 | #: qml/Fibonacci.qml:46 57 | msgctxt "Fibonacci|" 58 | msgid "The Fibonacci number: " 59 | msgstr "" 60 | 61 | #: qml/Fibonacci2.qml:27 62 | msgctxt "Fibonacci2|" 63 | msgid "Calculate the nth Fibonacci number" 64 | msgstr "" 65 | 66 | #: qml/Fibonacci2.qml:31 67 | msgctxt "Fibonacci2|" 68 | msgid "Your number" 69 | msgstr "" 70 | 71 | #: qml/Fibonacci2.qml:45 72 | msgctxt "Fibonacci2|" 73 | msgid "The Fibonacci number: " 74 | msgstr "" 75 | 76 | #: qml/FibonacciList.qml:30 77 | msgctxt "FibonacciList|" 78 | msgid "Row" 79 | msgstr "" 80 | 81 | #: qml/FibonacciList.qml:35 82 | msgctxt "FibonacciList|" 83 | msgid "Fibonacci number" 84 | msgstr "" 85 | 86 | #: qml/FibonacciList2.qml:29 87 | msgctxt "FibonacciList2|" 88 | msgid "Row" 89 | msgstr "" 90 | 91 | #: qml/FibonacciList2.qml:32 92 | msgctxt "FibonacciList2|" 93 | msgid "Fibonacci number" 94 | msgstr "" 95 | 96 | #: qml/FibonacciListKirigami.qml:29 97 | msgctxt "FibonacciListKirigami|" 98 | msgid "Row" 99 | msgstr "" 100 | 101 | #: qml/FibonacciListKirigami.qml:29 102 | msgctxt "FibonacciListKirigami|" 103 | msgid "Fibonacci number" 104 | msgstr "" 105 | 106 | #: qml/FileTreeView2.qml:36 107 | msgctxt "FileTreeView2|" 108 | msgid "‹" 109 | msgstr "" 110 | 111 | #: qml/FileTreeView2.qml:54 112 | msgctxt "FileTreeView2|" 113 | msgid "Name" 114 | msgstr "" 115 | 116 | #: qml/FileTreeView2.qml:57 117 | msgctxt "FileTreeView2|" 118 | msgid "Size" 119 | msgstr "" 120 | 121 | #: qml/FileTreeViewKirigami.qml:37 122 | msgctxt "FileTreeViewKirigami|" 123 | msgid "‹" 124 | msgstr "" 125 | 126 | #: qml/FileTreeViewKirigami.qml:55 127 | msgctxt "FileTreeViewKirigami|" 128 | msgid "Name" 129 | msgstr "" 130 | 131 | #: qml/FileTreeViewKirigami.qml:58 132 | msgctxt "FileTreeViewKirigami|" 133 | msgid "Size" 134 | msgstr "" 135 | 136 | #: src/main.cpp:240 137 | msgctxt "main|" 138 | msgid "Calculate the nth Fibonacci number" 139 | msgstr "" 140 | 141 | #: src/main.cpp:257 142 | msgctxt "main|" 143 | msgid "The Fibonacci number: " 144 | msgstr "" 145 | 146 | #: src/main.cpp:273 147 | msgctxt "main|" 148 | msgid "Row" 149 | msgstr "" 150 | 151 | #: src/main.cpp:275 152 | msgctxt "main|" 153 | msgid "Fibonacci number" 154 | msgstr "" 155 | 156 | #: src/main.cpp:284 157 | msgctxt "main|" 158 | msgid "Name" 159 | msgstr "" 160 | 161 | #: src/main.cpp:286 162 | msgctxt "main|" 163 | msgid "Size" 164 | msgstr "" 165 | 166 | #: src/main.cpp:422 167 | msgctxt "main|" 168 | msgid "Initial widget style." 169 | msgstr "" 170 | 171 | #: src/main.cpp:423 172 | msgctxt "main|" 173 | msgid "style" 174 | msgstr "" 175 | 176 | #: src/main.cpp:428 177 | msgctxt "main|" 178 | msgid "Initial tab." 179 | msgstr "" 180 | 181 | #: src/main.cpp:429 182 | msgctxt "main|" 183 | msgid "tab" 184 | msgstr "" 185 | -------------------------------------------------------------------------------- /poqm/ru/rqbgdemo_qt.po: -------------------------------------------------------------------------------- 1 | # Alexander Potashev , 2018. 2 | msgid "" 3 | msgstr "" 4 | "Project-Id-Version: \n" 5 | "PO-Revision-Date: 2018-08-27 04:07+0300\n" 6 | "Last-Translator: Alexander Potashev \n" 7 | "Language-Team: Russian \n" 8 | "Language: ru\n" 9 | "MIME-Version: 1.0\n" 10 | "Content-Type: text/plain; charset=UTF-8\n" 11 | "Content-Transfer-Encoding: 8bit\n" 12 | "X-Qt-Contexts: true\n" 13 | "Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n" 14 | "%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n" 15 | "X-Generator: Lokalize 2.0\n" 16 | 17 | #: qml/chart.qml:36 18 | msgctxt "chart|" 19 | msgid "time [s]" 20 | msgstr "" 21 | 22 | #: qml/chart.qml:42 23 | msgctxt "chart|" 24 | msgid "electric potential [V]" 25 | msgstr "" 26 | 27 | #: qml/DataAndChart.qml:85 28 | msgctxt "DataAndChart|" 29 | msgid "time" 30 | msgstr "" 31 | 32 | #: qml/DataAndChart.qml:89 33 | msgctxt "DataAndChart|" 34 | msgid "sin" 35 | msgstr "sin" 36 | 37 | #: qml/DataAndChart.qml:93 38 | msgctxt "DataAndChart|" 39 | msgid "cos" 40 | msgstr "cos" 41 | 42 | #: qml/DataAndChart.qml:104 43 | msgctxt "DataAndChart|" 44 | msgid "QtChart is not available." 45 | msgstr "" 46 | 47 | #: qml/Fibonacci.qml:28 48 | msgctxt "Fibonacci|" 49 | msgid "Calculate the nth Fibonacci number" 50 | msgstr "" 51 | 52 | #: qml/Fibonacci.qml:32 53 | msgctxt "Fibonacci|" 54 | msgid "Your number" 55 | msgstr "" 56 | 57 | #: qml/Fibonacci.qml:46 58 | msgctxt "Fibonacci|" 59 | msgid "The Fibonacci number: " 60 | msgstr "" 61 | 62 | #: qml/Fibonacci2.qml:27 63 | msgctxt "Fibonacci2|" 64 | msgid "Calculate the nth Fibonacci number" 65 | msgstr "" 66 | 67 | #: qml/Fibonacci2.qml:31 68 | msgctxt "Fibonacci2|" 69 | msgid "Your number" 70 | msgstr "" 71 | 72 | #: qml/Fibonacci2.qml:45 73 | msgctxt "Fibonacci2|" 74 | msgid "The Fibonacci number: " 75 | msgstr "" 76 | 77 | #: qml/FibonacciList.qml:30 78 | msgctxt "FibonacciList|" 79 | msgid "Row" 80 | msgstr "" 81 | 82 | #: qml/FibonacciList.qml:35 83 | msgctxt "FibonacciList|" 84 | msgid "Fibonacci number" 85 | msgstr "" 86 | 87 | #: qml/FibonacciList2.qml:29 88 | msgctxt "FibonacciList2|" 89 | msgid "Row" 90 | msgstr "" 91 | 92 | #: qml/FibonacciList2.qml:32 93 | msgctxt "FibonacciList2|" 94 | msgid "Fibonacci number" 95 | msgstr "" 96 | 97 | #: qml/FibonacciListKirigami.qml:29 98 | msgctxt "FibonacciListKirigami|" 99 | msgid "Row" 100 | msgstr "" 101 | 102 | #: qml/FibonacciListKirigami.qml:29 103 | msgctxt "FibonacciListKirigami|" 104 | msgid "Fibonacci number" 105 | msgstr "" 106 | 107 | #: qml/FileTreeView2.qml:36 108 | msgctxt "FileTreeView2|" 109 | msgid "‹" 110 | msgstr "" 111 | 112 | #: qml/FileTreeView2.qml:54 113 | msgctxt "FileTreeView2|" 114 | msgid "Name" 115 | msgstr "" 116 | 117 | #: qml/FileTreeView2.qml:57 118 | msgctxt "FileTreeView2|" 119 | msgid "Size" 120 | msgstr "" 121 | 122 | #: qml/FileTreeViewKirigami.qml:37 123 | msgctxt "FileTreeViewKirigami|" 124 | msgid "‹" 125 | msgstr "" 126 | 127 | #: qml/FileTreeViewKirigami.qml:55 128 | msgctxt "FileTreeViewKirigami|" 129 | msgid "Name" 130 | msgstr "" 131 | 132 | #: qml/FileTreeViewKirigami.qml:58 133 | msgctxt "FileTreeViewKirigami|" 134 | msgid "Size" 135 | msgstr "" 136 | 137 | #: src/main.cpp:240 138 | msgctxt "main|" 139 | msgid "Calculate the nth Fibonacci number" 140 | msgstr "" 141 | 142 | #: src/main.cpp:257 143 | msgctxt "main|" 144 | msgid "The Fibonacci number: " 145 | msgstr "" 146 | 147 | #: src/main.cpp:273 148 | msgctxt "main|" 149 | msgid "Row" 150 | msgstr "" 151 | 152 | #: src/main.cpp:275 153 | msgctxt "main|" 154 | msgid "Fibonacci number" 155 | msgstr "" 156 | 157 | #: src/main.cpp:284 158 | msgctxt "main|" 159 | msgid "Name" 160 | msgstr "" 161 | 162 | #: src/main.cpp:286 163 | msgctxt "main|" 164 | msgid "Size" 165 | msgstr "" 166 | 167 | #: src/main.cpp:422 168 | msgctxt "main|" 169 | msgid "Initial widget style." 170 | msgstr "" 171 | 172 | #: src/main.cpp:423 173 | msgctxt "main|" 174 | msgid "style" 175 | msgstr "" 176 | 177 | #: src/main.cpp:428 178 | msgctxt "main|" 179 | msgid "Initial tab." 180 | msgstr "" 181 | 182 | #: src/main.cpp:429 183 | msgctxt "main|" 184 | msgid "tab" 185 | msgstr "" 186 | --------------------------------------------------------------------------------