cxx-qt icon indicating copy to clipboard operation
cxx-qt copied to clipboard

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

Open ahayzen-kdab opened this issue 1 year ago • 2 comments

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".

  • [x] Add support in parser phase for C++Qt
  • [x] Add support in generation phases for a type that is foreign (it only needs to generate CXX bridges and the signal connect parts?)
  • [x] Ensure that type QButton;, fn show(self: Pin<&mut QButton>);, #[qsignal] fn clicked(self: Pin<&mut QButton>) work, but note that qproperty, inherit, qinvokable should not work ?
  • [ ] Change connections to be DirectConnection by default and make choosing a connection type as an unsafe closure (as QueuedConnection could have a mutable reference to something and be executed at any time in the future)

Consider any notes from #527

ahayzen-kdab avatar Jun 07 '23 09:06 ahayzen-kdab

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_guardstd::recursive_mutex lock() {

std::cout << "Locking" << std::endl;
return std::lock_guard<std::recursive_mutex>(m_mutex);

};

private: std::recursive_mutex m_mutex; };

class Object {};

class MyObject : public Locking {};

template <typename T, typename Derived = void> struct MaybeLock { MaybeLock(T &) {} };

template <typename T> struct MaybeLock<T, std::enable_if_t<std::is_base_of_v<Locking, T>>> { MaybeLock(Locking &locking) : m_lock(locking.lock()) {}

std::lock_guardstd::recursive_mutex m_lock; };

template <typename Object> void lock(Object &obj) { MaybeLock<Object> guard(obj); }

template <typename Object, typename... Args> std::function<void(Args...)> templateConnect(Object &obj, void (Object::*signal)(Args...), std::function<void(Object &, Args...)> function) { return [&, func = std::move(function)](Args... args) { MaybeLock<Object> maybeLock(obj);

func(obj, ::std::move(args)...);

}; }

int main(int arg, char **argv) { Locking myLock; lock(myLock);

int x; lock(x); }

ahayzen-kdab avatar Aug 02 '23 14:08 ahayzen-kdab

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

LeonMatthesKDAB avatar Jan 17 '24 14:01 LeonMatthesKDAB