Better_Software_Header_MobileBetter_Software_Header_Web

Find what you need - explore our website and developer resources

CXX-Qt 0.4 Released

#[cxx_qt::bridge]
mod my_object {
    unsafe extern "C++" {
        include!("cxx-qt-lib/qstring.h");
        type QString = cxx_qt_lib::QString;
    }

    #[cxx_qt::qobject]
    #[derive(Default)]
    pub struct MyObject {
        #[qproperty]
        number: i32,
        #[qproperty]
        string: QString,
    }
}
// In an invokable request a handle to the qt thread
let qt_thread = self.qt_thread();
// Spawn a Rust thread
std::thread::spawn(move || {
    let value = compute_value_on_rust_thread();
    // Use a closure to move the value and run the task on the Qt event loop
    qt_thread
        .queue(move |mut qobject| {
            // Happens on the Qt event loop
            qobject.set_value(value);
        })
        .unwrap();
});

About KDAB


3 Comments

26 - Nov - 2022

AdamSmith

1 - Feb - 2023

Andrew Hayzen

15 - Feb - 2023

DooMWhite

AndrewHayzen

Andrew Hayzen

Senior Software Engineer

Learn Rust

Learn more

Learn Modern C++

Learn more