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

what is the best way to test array contents in javascript? #186

Open
gmabey opened this issue Jan 6, 2021 · 3 comments
Open

what is the best way to test array contents in javascript? #186

gmabey opened this issue Jan 6, 2021 · 3 comments
Assignees
Labels
question Further information is requested

Comments

@gmabey
Copy link
Contributor

gmabey commented Jan 6, 2021

I have a qtprotobuf-generated class instance that I'm passing up to QML land.

One of its members is a QtProtobuf::uint32List and I want to test whether that list contains a certain value. I've tried includes() (the javascript array way) and contains() (more of a Qt thing) but neither work. The error reads:

TypeError: Property 'contains' of object QVariant(QtProtobuf::uint32List) is not a function

Is it currently possible to perform this test in a javascript function, within QML?

@gmabey gmabey added the question Further information is requested label Jan 6, 2021
@semlanik
Copy link
Owner

semlanik commented Jan 6, 2021

@gmabey this should work for uint32 lists. I checked this on RepeatedUIntMessage from tests and it works.

message RepeatedUIntMessage {
    repeated uint32 testRepeatedInt = 1;
}
    RepeatedUIntMessage {
        id: testMsg
        testRepeatedInt: [5, 4, 3, 2, 1]
    }

    ...
    console.log(testMsg.testRepeatedInt.includes(3)) // Prints true
    ...

But there is an issue with "transparent" types, so this I need to fix.

@gmabey
Copy link
Contributor Author

gmabey commented Feb 2, 2021

What version did you do this test with? I'm still getting that error (in the original post).

@semlanik
Copy link
Owner

semlanik commented Feb 3, 2021

Recent master, but probably there is something that is specific for the message you check. So if you could give me a raw message structure I could dig further.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants