mirror of
https://github.com/qmlnet/qmlnet.git
synced 2026-05-15 14:15:54 -06:00
[GH-ISSUE #205] How to access elements of List<string> or string[] returned from C# function in QML JS #130
Labels
No labels
bug
enhancement
help wanted
help wanted
pull-request
question
todo
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: github-starred/qmlnet#130
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @FieryRider on GitHub (May 30, 2020).
Original GitHub issue: https://github.com/qmlnet/qmlnet/issues/205
Basically I have function in C# that returns
string[]. I've registered the class as a type in QML and I can call the function from JS in QML. But I don't know how to loop through the values of the returnedstring[]in JS.When I
console.log()the returned value I getqml: String[](0x555d44926470)@pauldotknopf commented on GitHub (May 30, 2020):
Use
Net.toListModel(yourValue)to work with it.Or,
Net.toVariantList(yourValue).@pauldotknopf commented on GitHub (May 30, 2020):
You can also use
Net.listForEach(yourValue, function(val) {})to enumerate it.@FieryRider commented on GitHub (May 30, 2020):
Net.toListModel(yourValue)andNet.listForEach(yourValue, (val) => {})worked for a C#List<>.Net.toVariantList(yourValue)gave errorTypeError: Property 'toVariantList' of object JsNetObject(0x5600f4c52f90) is not a function. I guess it's something that is not in the0.10.1release.For a C#
string[]none of these worked, giving meParameter is not a type that be enumerated.so I had to use standardforloopfor (let i = 0; i < arr.length; i++) { console.log(arr.get(i)) }Thanks.