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 qml_register_uncreatable_type #227

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

mhoff12358
Copy link

This allows for registering structs that don't implement Default, mirroring C++'s QQmlEngine::qmlRegisterUncreatableType.

All of the qmetaobject crate tests pass, but I didn't run tests in any other sub-crates.

Copy link
Member

@ogoffart ogoffart left a comment

Choose a reason for hiding this comment

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

Thanks for the patch! This looks good.
The only detail is the last creation_reason parameter, which should be a QString

uri: &CStr,
version_major: u32,
version_minor: u32,
qml_name: &CStr,
no_creation_reason: &CStr,
Copy link
Member

Choose a reason for hiding this comment

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

This should be a QString, since it is a user visible string, and that's also what Qt uses.

Copy link
Author

Choose a reason for hiding this comment

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

Ah, you're right. I was following the pattern of the other CStr arguments, but Qt does seem to use both raw C strings and QStrings for whatever reason.

Fixed.

Copy link
Collaborator

Choose a reason for hiding this comment

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

since it is a user visible string

I don't think that argument is really any valid, to be honest :)
Can't imagine a user reading the "uncreatable type" error at runtime.

This allows for registering structs that don't implement Default,
mirroring C++'s QQmlEngine::qmlRegisterUncreatableType.
qmetaobject/src/qtdeclarative.rs Show resolved Hide resolved
qmetaobject/src/qtdeclarative.rs Outdated Show resolved Hide resolved
qmetaobject/src/qtdeclarative.rs Outdated Show resolved Hide resolved
qmetaobject/tests/tests.rs Outdated Show resolved Hide resolved
qmetaobject/tests/tests.rs Show resolved Hide resolved
listName[listLen+nameLen+1] = '\0';*/
// END

int parserStatusCast = meta_object && qmeta_inherits(meta_object, &QQuickItem::staticMetaObject)
Copy link
Collaborator

Choose a reason for hiding this comment

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

@ogoffart Why would we even need a parserStatus for uncreatable types?

Copy link
Author

Choose a reason for hiding this comment

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

I was just following qml_register_type. I replace this with -1, which seems to be the default. Can you confirm that it's correct?

Copy link
Author

Choose a reason for hiding this comment

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

Ping, can you confirm that the default value of -1 is correct here?

Copy link
Member

Choose a reason for hiding this comment

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

I don't know. The Qt code does put a value there but i don't know if it is usefull.
The type might not be created by QML but maybe it can still be cast? I have no idea

@leo60228
Copy link

Is there any update on this PR?

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.

4 participants