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

Direct signals-slots connection between two QObjects #1200

Open
LeonMatthesKDAB opened this issue Feb 27, 2025 · 0 comments
Open

Direct signals-slots connection between two QObjects #1200

LeonMatthesKDAB opened this issue Feb 27, 2025 · 0 comments
Labels
⬆️ feature New feature or request

Comments

@LeonMatthesKDAB
Copy link
Collaborator

As mentioned in #1198 , it would be good if we could connect directly between signals and slots of QObjects.

The new Qt API for QObject::connect has the issue that it is heavily templated, which doesn't lend itself well to a general solution in CXX.

However, the older QObject APIs that take const char* still exist: https://doc.qt.io/qt-6/qobject.html#connect-1

If we could replicate the SLOT and SIGNAL macros, it would be possible to expose this function ourselves.
Luckily, this doesn't seem hard to do, the Qt sources show that these macros just end up pre-pending "1" and "2" to the signature (and call qFlagLocation in DEBUG).

We could provide our own macros that add these prefixes, and also translate the signature from C++ to Rust, so that:

QObject::connect(scrollBar, SIGNAL(valueChanged(int)),
                 label,  SLOT(setNum(int)));

would become:

QObject::connect(scrollBar, signal!(valueChanged(i32)),
                 label, slot!(setNum(i32)));

Note that the macro should probably return NewType wrappers around &'static str so that we add a bit more type safety.

@LeonMatthesKDAB LeonMatthesKDAB added the ⬆️ feature New feature or request label Feb 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⬆️ feature New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant