Skip to content

Add #[derive(QEnum)] #42

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

Merged
merged 1 commit into from
Jul 12, 2019
Merged

Add #[derive(QEnum)] #42

merged 1 commit into from
Jul 12, 2019

Conversation

Guiguiprim
Copy link
Contributor

Only add the meta-object, not the property support:

  • We can register a enum in the QML engine and use it from QML side
  • We can not yet use it as a object property

Enum values are stored in an array of u32, so 32 is the maximal size that will correctly work (moc doesn't check...). So I choice to force the use of the attribute #[repr(*)] limited to u8, u16, u32, i8, i16, i32.

I needed to change QMetaObject.static_metacall to an option type as an extern "C" fn pointer can not be set to null (see rust-lang/rust#8730). The namespace meta-object doesn't have an associated static_metacall function so we need to be able to set it to null.

I work with Qt 5.12.1 so my moc output example is in version 8. I had to bump the version from 7 to 8 to make it work. I don't know if it possible to make it work in version 7.

I'm still working on the property part.

@Guiguiprim
Copy link
Contributor Author

I see that your continuous integration tests for Qt version 5.8, 5.9 and 5.10.

And they all fail... 😢
I guess that the bump in meta-object version is recent. I will need to have a look at it with an older version of Qt than my 5.12.

@ogoffart
Copy link
Member

I guess it is best to keep using the metaobject revision version 7.
It is totally possible to make it work in version 7 the only change is that there is no alias.

@@ -445,7 +455,8 @@ pub struct QMetaObject {
pub superdata: *const QMetaObject,
pub string_data: *const u8,
pub data: *const u32,
pub static_metacall: extern "C" fn(o: *mut c_void, c: u32, idx: u32, a: *const *mut c_void),
pub static_metacall:
Option<extern "C" fn(o: *mut c_void, c: u32, idx: u32, a: *const *mut c_void)>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the Option<> has the same size as the exten fn, that's perfectly fine and there is no bug in rust.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extern "C" fn seems to be not nullable, so Option<extern "C" fn> should be optimized to the same size. I will check that they do.
From the link I posted, it appears to be the way to go about it.

At least the tests run just fine...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Guiguiprim
Copy link
Contributor Author

Yep, works for me in version 7 after removing the alias. Thanks

@ogoffart
Copy link
Member

Looks great!

@ogoffart ogoffart merged commit bc2e24f into woboq:master Jul 12, 2019
@Guiguiprim Guiguiprim deleted the enum-metaobject branch July 15, 2019 10:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants