cxx-qt
cxx-qt copied to clipboard
Add support for `extern "C++Qt"` with type, fn, and signals
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
C++ prototypes of the mixins / templates route
#include
#include
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); }
TODO: Check correct marker Traits (Send, Sync, etc.)