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.

Automatically converting to camel or snake case can be done through an attribute at the block level.

QObjects

QObject types that are defined in C++ can be made available to Rust, by declaring them as opaque types with a #[qobject] attribute.

📝 Note: Types inside extern "C++Qt" are currently required to have a #[qobject] attribute

#[cxx_qt::bridge]
mod ffi {
    extern "C++Qt" {
        include!(<QtWidgets/QPushButton>);
        #[qobject]
        type QPushButton;
    }
}

Methods

Methods can be specified on the QObject 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>);
        #[qobject]
        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>);
        #[qobject]
        type QPushButton;

        #[qsignal]
        fn clicked(self: Pin<&mut QPushButton>, checked: bool);
    }
}

This then causes CXX-Qt to generate Rust methods to emit and connect to the #[qsignal], 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