Skip to content

Commit

Permalink
examples: update all examples to use safe extern "RustQt"
Browse files Browse the repository at this point in the history
  • Loading branch information
ahayzen-kdab committed Feb 27, 2025
1 parent 45473f3 commit 69abab5
Show file tree
Hide file tree
Showing 23 changed files with 41 additions and 41 deletions.
2 changes: 1 addition & 1 deletion crates/cxx-qt-macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use cxx_qt_gen::{write_rust, GeneratedRustBlocks, Parser};
/// ```rust
/// #[cxx_qt::bridge(namespace = "cxx_qt::my_object")]
/// mod qobject {
/// unsafe extern "RustQt" {
/// extern "RustQt" {
/// #[qobject]
/// # // Note that we can't use properties as this confuses the linker on Windows
/// type MyObject = super::MyObjectRust;
Expand Down
2 changes: 1 addition & 1 deletion crates/cxx-qt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub trait CxxQtType {
/// # // FIXME: test doesn't link correctly on Windows
/// #[cxx_qt::bridge]
/// mod qobject {
/// unsafe extern "RustQt" {
/// extern "RustQt" {
/// #[qobject]
/// type MyStruct = super::MyStructRust;
///
Expand Down
4 changes: 2 additions & 2 deletions examples/demo_threading/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub mod qobject {
// Enabling threading on the qobject
impl cxx_qt::Threading for EnergyUsage {}

unsafe extern "RustQt" {
extern "RustQt" {
/// A new sensor has been detected
#[qsignal]
#[cxx_name = "sensorAdded"]
Expand All @@ -44,7 +44,7 @@ pub mod qobject {
fn sensor_removed(self: Pin<&mut EnergyUsage>, uuid: QString);
}

unsafe extern "RustQt" {
extern "RustQt" {
/// A Q_INVOKABLE that returns the current power usage for a given uuid
#[qinvokable]
#[cxx_name = "sensorPower"]
Expand Down
2 changes: 1 addition & 1 deletion examples/qml_features/rust/src/containers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub mod qobject {
type QVector_i32 = cxx_qt_lib::QVector<i32>;
}

unsafe extern "RustQt" {
extern "RustQt" {
#[qobject]
#[qml_element]
#[qproperty(QString, string_hash, cxx_name = "stringHash")]
Expand Down
12 changes: 6 additions & 6 deletions examples/qml_features/rust/src/custom_base_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pub mod qobject {
}
// ANCHOR_END: book_qsignals_inherit

unsafe extern "RustQt" {
extern "RustQt" {
/// Log the state of the abstract class
#[qinvokable]
#[cxx_virtual]
Expand Down Expand Up @@ -120,14 +120,14 @@ pub mod qobject {
}

// ANCHOR: book_inherit_clear_signature
unsafe extern "RustQt" {
extern "RustQt" {
/// Clear the rows in the QAbstractListModel
#[qinvokable]
pub fn clear(self: Pin<&mut CustomBaseClass>);
}
// ANCHOR_END: book_inherit_clear_signature

unsafe extern "RustQt" {
extern "RustQt" {
/// Multiply the number in the row with the given index by the given factor
#[qinvokable]
pub fn multiply(self: Pin<&mut CustomBaseClass>, index: i32, factor: f64);
Expand Down Expand Up @@ -217,15 +217,15 @@ pub mod qobject {

// QAbstractListModel implementation
// ANCHOR: book_inherit_data_signature
unsafe extern "RustQt" {
extern "RustQt" {
#[qinvokable]
#[cxx_override]
fn data(self: &CustomBaseClass, index: &QModelIndex, role: i32) -> QVariant;
}
// ANCHOR_END: book_inherit_data_signature

// ANCHOR: book_inherit_can_fetch_more_signature
unsafe extern "RustQt" {
extern "RustQt" {
/// Return whether the base class can fetch more
// Example of overriding a C++ virtual method and calling the base class implementation.
#[qinvokable]
Expand All @@ -235,7 +235,7 @@ pub mod qobject {
}
// ANCHOR_END: book_inherit_can_fetch_more_signature

unsafe extern "RustQt" {
extern "RustQt" {
/// Return the role names for the QAbstractListModel
#[qinvokable]
#[cxx_override]
Expand Down
2 changes: 1 addition & 1 deletion examples/qml_features/rust/src/externcxxqt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub mod ffi {
pub(self) fn triggeredPrivateSignal(self: Pin<&mut ExternalQObject>);
}

unsafe extern "RustQt" {
extern "RustQt" {
#[qobject]
#[qml_element]
#[qproperty(u32, count)]
Expand Down
6 changes: 3 additions & 3 deletions examples/qml_features/rust/src/invokables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub mod qobject {
type QColor = cxx_qt_lib::QColor;
}

unsafe extern "RustQt" {
extern "RustQt" {
#[qobject]
#[qml_element]
type RustInvokables = super::RustInvokablesRust;
Expand All @@ -41,7 +41,7 @@ pub mod qobject {
// ANCHOR_END: book_namespaced_qenum

// ANCHOR: book_invokable_signature
unsafe extern "RustQt" {
extern "RustQt" {
/// Immutable invokable method that returns the QColor
#[qinvokable]
#[cxx_name = "loadColor"]
Expand All @@ -64,7 +64,7 @@ pub mod qobject {
// ANCHOR_END: book_invokable_signature

// ANCHOR: book_cpp_method_signature
unsafe extern "RustQt" {
extern "RustQt" {
/// C++ only method which returns the red value
#[cxx_name = "redValue"]
fn red_value(self: &RustInvokables) -> f32;
Expand Down
8 changes: 4 additions & 4 deletions examples/qml_features/rust/src/multiple_qobjects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub mod qobject {
// Enabling threading on the qobject
impl cxx_qt::Threading for FirstObject {}

unsafe extern "RustQt" {
extern "RustQt" {
/// Accepted Q_SIGNAL
#[qsignal]
fn accepted(self: Pin<&mut FirstObject>);
Expand All @@ -38,7 +38,7 @@ pub mod qobject {
fn rejected(self: Pin<&mut FirstObject>);
}

unsafe extern "RustQt" {
extern "RustQt" {
/// A Q_INVOKABLE on the first QObject which increments a counter
#[qinvokable]
fn increment(self: Pin<&mut FirstObject>);
Expand All @@ -55,7 +55,7 @@ pub mod qobject {
// Enabling threading on the qobject
impl cxx_qt::Threading for SecondObject {}

unsafe extern "RustQt" {
extern "RustQt" {
/// Accepted Q_SIGNAL
#[qsignal]
fn accepted(self: Pin<&mut SecondObject>);
Expand All @@ -65,7 +65,7 @@ pub mod qobject {
fn rejected(self: Pin<&mut SecondObject>);
}

unsafe extern "RustQt" {
extern "RustQt" {
/// A Q_INVOKABLE on the second QObject which increments a counter
#[qinvokable]
fn increment(self: Pin<&mut SecondObject>);
Expand Down
6 changes: 3 additions & 3 deletions examples/qml_features/rust/src/naming.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/// A CXX-Qt bridge containing renamed and namespaced types
#[cxx_qt::bridge]
pub mod qobject {
unsafe extern "RustQt" {
extern "RustQt" {
#[qobject]
#[qml_element]
#[qproperty(i32, num, cxx_name = "numberProp")]
Expand All @@ -17,15 +17,15 @@ pub mod qobject {
type NamedObject = super::NamedObjectRust;
}

unsafe extern "RustQt" {
extern "RustQt" {
#[qinvokable]
#[cxx_name = "increment"]
#[rust_name = "plus_one"]
fn increment_number(self: Pin<&mut NamedObject>);
}

#[auto_cxx_name]
unsafe extern "RustQt" {
extern "RustQt" {
#[qinvokable]
fn get_num(self: &NamedObject) -> i32;
}
Expand Down
2 changes: 1 addition & 1 deletion examples/qml_features/rust/src/nested_qobjects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub mod qobject {
unsafe fn called(self: Pin<&mut OuterObject>, inner: *mut InnerObject);
}

unsafe extern "RustQt" {
extern "RustQt" {
/// Print the count of the given inner QObject
///
/// # Safety
Expand Down
2 changes: 1 addition & 1 deletion examples/qml_features/rust/src/properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub mod qobject {
type QUrl = cxx_qt_lib::QUrl;
}

unsafe extern "RustQt" {
extern "RustQt" {
// ANCHOR: book_properties_signature
#[qobject]
#[qml_element]
Expand Down
2 changes: 1 addition & 1 deletion examples/qml_features/rust/src/serialisation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub mod qobject {
type QString = cxx_qt_lib::QString;
}

unsafe extern "RustQt" {
extern "RustQt" {
#[qobject]
#[qml_element]
#[qproperty(i32, number)]
Expand Down
6 changes: 3 additions & 3 deletions examples/qml_features/rust/src/signals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub mod qobject {
}

// ANCHOR: book_signals_block
unsafe extern "RustQt" {
extern "RustQt" {
/// A Q_SIGNAL emitted when a connection occurs
#[qsignal]
fn connected(self: Pin<&mut RustSignals>, url: &QUrl);
Expand All @@ -35,7 +35,7 @@ pub mod qobject {
// ANCHOR_END: book_signals_block

// ANCHOR: book_signals_struct
unsafe extern "RustQt" {
extern "RustQt" {
#[qobject]
#[qml_element]
#[qproperty(bool, logging_enabled)]
Expand All @@ -44,7 +44,7 @@ pub mod qobject {
// ANCHOR_END: book_signals_struct

// ANCHOR: book_rust_obj_impl
unsafe extern "RustQt" {
extern "RustQt" {
/// Connect to the given url
#[qinvokable]
fn connect(self: Pin<&mut RustSignals>, url: &QUrl);
Expand Down
2 changes: 1 addition & 1 deletion examples/qml_features/rust/src/singleton.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// ANCHOR: book_macro_code
#[cxx_qt::bridge]
pub mod qobject {
unsafe extern "RustQt" {
extern "RustQt" {
#[qobject]
#[qml_element]
#[qml_singleton]
Expand Down
2 changes: 1 addition & 1 deletion examples/qml_features/rust/src/threading.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub mod qobject {
impl cxx_qt::Threading for ThreadingWebsite {}
// ANCHOR_END: book_threading_trait

unsafe extern "RustQt" {
extern "RustQt" {
/// Swap the URL between kdab.com and github.com
#[qinvokable]
#[cxx_name = "changeUrl"]
Expand Down
2 changes: 1 addition & 1 deletion examples/qml_features/rust/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub mod ffi {
fn qvariantValueOrDefault(variant: &QVariant) -> CustomStruct;
}

unsafe extern "RustQt" {
extern "RustQt" {
#[qobject]
#[qml_element]
#[qproperty(bool, boolean)]
Expand Down
4 changes: 2 additions & 2 deletions examples/qml_minimal/rust/src/cxxqt_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub mod qobject {
// ANCHOR_END: book_qstring_import

// ANCHOR: book_rustobj_struct_signature
unsafe extern "RustQt" {
extern "RustQt" {
// The QObject definition
// We tell CXX-Qt that we want a QObject class with the name MyObject
// based on the Rust struct MyObjectRust.
Expand All @@ -36,7 +36,7 @@ pub mod qobject {
// ANCHOR_END: book_rustobj_struct_signature

// ANCHOR: book_rustobj_invokable_signature
unsafe extern "RustQt" {
extern "RustQt" {
// Declare the invokable methods we want to expose on the QObject
#[qinvokable]
#[cxx_name = "incrementNumber"]
Expand Down
2 changes: 1 addition & 1 deletion examples/qml_multi_crates/rust/main/src/main_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub mod qobject {
type QString = cxx_qt_lib::QString;
}

unsafe extern "RustQt" {
extern "RustQt" {
#[qobject]
#[qml_element]
#[qproperty(QString, string)]
Expand Down
2 changes: 1 addition & 1 deletion examples/qml_multi_crates/rust/sub1/src/sub1_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub mod qobject {
type QString = cxx_qt_lib::QString;
}

unsafe extern "RustQt" {
extern "RustQt" {
#[qobject]
#[qml_element]
#[qproperty(QString, string)]
Expand Down
2 changes: 1 addition & 1 deletion examples/qml_multi_crates/rust/sub2/src/sub2_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub mod qobject {
type QString = cxx_qt_lib::QString;
}

unsafe extern "RustQt" {
extern "RustQt" {
#[qobject]
#[qml_element]
#[qproperty(QString, string)]
Expand Down
2 changes: 1 addition & 1 deletion tests/basic_cxx_qt/rust/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ mod qobject {
type QString = cxx_qt_lib::QString;
}

unsafe extern "RustQt" {
extern "RustQt" {
#[qobject]
#[qproperty(i32, number)]
#[qproperty(QString, string)]
Expand Down
4 changes: 2 additions & 2 deletions tests/basic_cxx_qt/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ mod qobject {
type QString = cxx_qt_lib::QString;
}

unsafe extern "RustQt" {
extern "RustQt" {
#[qobject]
#[qproperty(i32, number)]
#[qproperty(QString, string)]
Expand All @@ -28,7 +28,7 @@ mod qobject {
impl cxx_qt::Threading for MyObject {}

// Note that we are only testing with C++ here so we don't need qinvokable
unsafe extern "RustQt" {
extern "RustQt" {
#[cxx_name = "doubleNumberSelf"]
fn double_number_self(self: Pin<&mut MyObject>);

Expand Down
4 changes: 2 additions & 2 deletions tests/basic_cxx_qt/rust/src/naming.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ mod qobject {
type QString = cxx_qt_lib::QString;
}

unsafe extern "RustQt" {
extern "RustQt" {
#[qobject]
#[qproperty(i32, number)]
#[qproperty(QString, string)]
Expand All @@ -27,7 +27,7 @@ mod qobject {
}

// Note that we are only testing with C++ here so we don't need qinvokable
unsafe extern "RustQt" {
extern "RustQt" {
#[cxx_name = "sayHi"]
fn say_hi(self: &NamedObject, string: &QString, number: i32);

Expand Down

0 comments on commit 69abab5

Please sign in to comment.