Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add extern "Qt" - allow signals on existing Qt classes #527

Closed
ahayzen-kdab opened this issue May 1, 2023 · 6 comments
Closed

Add extern "Qt" - allow signals on existing Qt classes #527

ahayzen-kdab opened this issue May 1, 2023 · 6 comments
Assignees
Labels
🤔 discussion Feedback welcome ⬆️ feature New feature or request 🥳🎉 1.0 This issue is part of stabilization for 1.0 release

Comments

@ahayzen-kdab
Copy link
Collaborator

In #485 we start adding support for (dis)connecting in Rust, this works for QObjects defined in Rust.

However a QObject could be defined outside of Rust and we might want to (dis)connect from it's signals.

A possible solution would be to explore having an extern "Qt" block again, and then changing signals away from an enum to methods.

unsafe extern "Qt" {
   #[qsignal]
    fn my_signal(self: &MyQObject, param: QString);
}

#[cxx_qt::qobject]
struct MyQObject;

unsafe extern "Qt" {
    type QButton;
    #[qsignal]
    fn my_signal(self: &QButton, param: QString);
}

This would keep the way of defining a signal consistent to Rust and C++ QObjects, which then means the generation is the same for generating on_SIGNAL.

For the emit side we would likely need to consider removing converters #289 or the Rust my_signal would be renamed in CXX to the emitMySignal that performs any conversion.

I also wonder would we then put the inherit macro in this block too ?

unsafe extern "Qt" {
   #[qsignal]
    fn my_signal(self: &MyQObject, param: QString);

    #[inherit]
    #[cxx_name = "hasChildren"]
    fn has_children_super(self: &MyQObject, parent: &QModelIndex) -> bool;
}

#[cxx_qt::qobject(base = "QAbstractItemModel")]
struct MyQObject;

Guess one of the questions with that would be, is it qobject::MyQObject or MyQObject for the type ?

cc @LeonMatthesKDAB

@ahayzen-kdab ahayzen-kdab added ⬆️ feature New feature or request 🤔 discussion Feedback welcome labels May 1, 2023
@LeonMatthesKDAB
Copy link
Collaborator

For both signals, and inherit, we'll want to use qobject::MyQObject, as that's what they'll end up on. 🤔

@ahayzen-kdab
Copy link
Collaborator Author

For both signals, and inherit, we'll want to use qobject::MyQObject, as that's what they'll end up on. thinking

My question would then be, what happens for foreign QObjects ? eg type QButton ? Is the type here always referring to the TQt variant as there isn't a Rust version ? So for these you would use just T where as Rust based ones would use qobject::T.

@ahayzen-kdab
Copy link
Collaborator Author

We should figure out the larger question around T vs TQt and whether we want an extern "Qt" block in #531 first.

@LeonMatthesKDAB LeonMatthesKDAB added the 🥳🎉 1.0 This issue is part of stabilization for 1.0 release label May 29, 2023
@LeonMatthesKDAB LeonMatthesKDAB changed the title Consider API for signals to allows for declaring signals on foreign QObjects Add extern "Qt" - allow signals on existing Qt classes May 29, 2023
@LeonMatthesKDAB
Copy link
Collaborator

For results, see #555.

TL;DR: We'll want to introduce an extern "Qt" block as proposed in this issue + a extern "RustQt" for Rust-defined QObjects.

@ahayzen-kdab
Copy link
Collaborator Author

This can be combined into #577

@ahayzen-kdab ahayzen-kdab self-assigned this Jul 27, 2023
@ahayzen-kdab
Copy link
Collaborator Author

Close in favour of #577

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤔 discussion Feedback welcome ⬆️ feature New feature or request 🥳🎉 1.0 This issue is part of stabilization for 1.0 release
Projects
Status: Done
Development

No branches or pull requests

2 participants