extern "C++Qt"
#[cxx_qt::bridge]
mod ffi {
extern "C++Qt" {
}
}
The extern "C++Qt"
section of a CXX-Qt bridge declares Qt types and signatures to be made available to Rust,
and gives the paths of the headers which contain the corresponding Qt declarations.
A bridge module may contain zero or more extern "C++Qt"
blocks.
This complements the extern "C++"
CXX section
but allows for declaring Qt specific features on C++ types.
QObjects
Types defined in C++ that are made available to Rust, but only behind an indirection.
This is the same as CXX Opaque C++ types.
#[cxx_qt::bridge]
mod ffi {
extern "C++Qt" {
include!(<QtWidgets/QPushButton>);
type QPushButton;
}
}
Methods
Methods can be specified on the Qt type in the same way as extern "RustQt"
blocks.
This is the same as CXX Functions and member functions.
#[cxx_qt::bridge]
mod ffi {
unsafe extern "C++" {
include!("cxx-qt-lib/qstring.h");
type QString = cxx_qt_lib::QString;
}
extern "C++Qt" {
include!(<QtWidgets/QPushButton>);
type QPushButton;
fn text(self: &QPushButton) -> QString;
fn setText(self: Pin<&mut QPushButton>, text: &QString);
}
}
Signals
Signals can be specified on the Qt type in the same way as extern "RustQt"
blocks.
#[cxx_qt::bridge]
mod ffi {
extern "C++Qt" {
include!(<QtWidgets/QPushButton>);
type QPushButton;
#[qsignal]
fn clicked(self: Pin<&mut QPushButton>, checked: bool);
}
}
This then causes CXX-Qt to generate Rust methods to connect to the #[qsignal]
with a closure,
in the same way as a #[qsignal]
in a extern "RustQt"
block.
Note using
pub(self)
as the visibility of the signal allows for declaring private signals