KDAB / cxx-qt

Safe interop between Rust and Qt
https://kdab.github.io/cxx-qt/book/
1.08k stars 77 forks source link

Add support for `extern "C++Qt"` with type, fn, and signals #577

Closed ahayzen-kdab closed 1 month ago

ahayzen-kdab commented 1 year ago

Our current generation is mostly about the extern "RustQt" side, once #557 is done we'll have extern "RustQt" with support for inherit and signals. Then #558 adds support for invokables and #559 for type and properties.

But we also want to support foreign types (eg type QButton), so we need to support extern "C++Qt".

Consider any notes from #527

ahayzen-kdab commented 1 year ago
C++ prototypes of the mixins / templates route #include #include #include #include #include #include #include using namespace std; using namespace std::chrono; class Locking { public: std::lock_guard lock() { std::cout << "Locking" << std::endl; return std::lock_guard(m_mutex); }; private: std::recursive_mutex m_mutex; }; class Object {}; class MyObject : public Locking {}; template struct MaybeLock { MaybeLock(T &) {} }; template struct MaybeLock>> { MaybeLock(Locking &locking) : m_lock(locking.lock()) {} std::lock_guard m_lock; }; template void lock(Object &obj) { MaybeLock guard(obj); } template std::function templateConnect(Object &obj, void (Object::*signal)(Args...), std::function function) { return [&, func = std::move(function)](Args... args) { MaybeLock maybeLock(obj); func(obj, ::std::move(args)...); }; } int main(int arg, char **argv) { Locking myLock; lock(myLock); int x; lock(x); }
LeonMatthesKDAB commented 10 months ago

TODO: Check correct marker Traits (Send, Sync, etc.)