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

Allow for defining trivial types in C++Qt blocks #1180

Open
ahayzen-kdab opened this issue Feb 7, 2025 · 3 comments
Open

Allow for defining trivial types in C++Qt blocks #1180

ahayzen-kdab opened this issue Feb 7, 2025 · 3 comments
Labels
🤔 discussion Feedback welcome

Comments

@ahayzen-kdab
Copy link
Collaborator

ahayzen-kdab commented Feb 7, 2025

Currently cxx-qt-lib's advantage is that we can define a trivial type as we alias the C++ type to a struct with a known size and assert it on either side.

What if we could do the following

#[cxx_qt::bridge]
mod ffi {
   unsafe extern "C++Qt" {
     #[cxx_qt_size(usize, usize, usize)] // maybe alignment too?
     type QString;
   }
}

Then could the bridge automatically generate the struct with the MaybeUninit and the assert on the C++ side?

There would then be questions over automatically implementing Clone/Drop/Default etc? Some of these should probably be attributes as they affect the movable asserts on the C++ side.

@ahayzen-kdab ahayzen-kdab added the 🤔 discussion Feedback welcome label Feb 7, 2025
@ahayzen-kdab
Copy link
Collaborator Author

Could we even always implement a Drop and then in the C++ have a static check whether it needs to be called or not?

Then things like Clone/Default could be up to the developer / another attribute.

@LeonMatthesKDAB
Copy link
Collaborator

I can definitely see how that would be nice to have.
However, it would mostly be a convenience for cxx-qt-lib...

If anything, this really belongs into CXX itself, so I wouldn't want to add this to CXX-Qt, as it would be public API surface that we need to maintain...

@ahayzen-kdab
Copy link
Collaborator Author

ahayzen-kdab commented Feb 12, 2025

Thing is some of the asserts like the QTypeInfo::isRelocatable would be Qt specific asserts 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤔 discussion Feedback welcome
Projects
None yet
Development

No branches or pull requests

2 participants