diff --git a/src/cpp/qsettingscxx.h b/src/cpp/qsettingscxx.h new file mode 100644 index 0000000..ddc9340 --- /dev/null +++ b/src/cpp/qsettingscxx.h @@ -0,0 +1,24 @@ +#pragma once + +#include + +#include "rust/cxx.h" + +class QSettingsCXX : public QSettings +{ +public: + explicit QSettingsCXX(QObject* parent = nullptr) + : QSettings(parent) + { + } + + // Can't define in CXX as they are protected + // so crate public methods that are proxied + void setValue(QString key, QString value) + { + QSettings::setValue(key, value); + } + + void sync() { QSettings::sync(); } + +}; diff --git a/src/rust/settings.rs b/src/rust/settings.rs new file mode 100644 index 0000000..2d3ee70 --- /dev/null +++ b/src/rust/settings.rs @@ -0,0 +1,34 @@ +#[cxx_qt::bridge] +mod settings { + + unsafe extern "C++" { + include!("qsettingscxx.h"); + include!("cxx-qt-lib/qstring.h"); + type QString = cxx_qt_lib::QString; + } + + #[derive(Clone)] + #[cxx_qt::qobject(base = "QSettingsCXX")] + pub struct Settings { + #[qproperty] + name: QString, + #[qproperty] + kind: QString, + } + + impl Default for Settings { + fn default() -> Self { + Self { + name: QString::from(""), + kind: QString::from(""), + } + } + } + + impl qobject::Settings { + #[qinvokable] + pub fn activate(self: Pin<&mut Self>) { + println!("{}", self.name()); + } + } +}