[GH-ISSUE #205] How to access elements of List<string> or string[] returned from C# function in QML JS #130

Closed
opened 2026-05-05 11:06:15 -06:00 by gitea-mirror · 3 comments
Owner

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 returned string[] in JS.
When I console.log() the returned value I get qml: String[](0x555d44926470)

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 returned `string[]` in JS. When I `console.log()` the returned value I get `qml: String[](0x555d44926470)`
Author
Owner

@pauldotknopf commented on GitHub (May 30, 2020):

Use Net.toListModel(yourValue) to work with it.

Or, Net.toVariantList(yourValue).

<!-- gh-comment-id:636261214 --> @pauldotknopf commented on GitHub (May 30, 2020): Use ```Net.toListModel(yourValue)``` to work with it. Or, ```Net.toVariantList(yourValue)```.
Author
Owner

@pauldotknopf commented on GitHub (May 30, 2020):

You can also use Net.listForEach(yourValue, function(val) {}) to enumerate it.

<!-- gh-comment-id:636262939 --> @pauldotknopf commented on GitHub (May 30, 2020): You can also use ```Net.listForEach(yourValue, function(val) {})``` to enumerate it.
Author
Owner

@FieryRider commented on GitHub (May 30, 2020):

Net.toListModel(yourValue) and Net.listForEach(yourValue, (val) => {}) worked for a C# List<>. Net.toVariantList(yourValue) gave error TypeError: Property 'toVariantList' of object JsNetObject(0x5600f4c52f90) is not a function. I guess it's something that is not in the 0.10.1 release.
For a C# string[] none of these worked, giving me Parameter is not a type that be enumerated. so I had to use standard for loop for (let i = 0; i < arr.length; i++) { console.log(arr.get(i)) }
Thanks.

<!-- gh-comment-id:636372161 --> @FieryRider commented on GitHub (May 30, 2020): `Net.toListModel(yourValue)` and `Net.listForEach(yourValue, (val) => {})` worked for a C# `List<>`. `Net.toVariantList(yourValue)` gave error `TypeError: Property 'toVariantList' of object JsNetObject(0x5600f4c52f90) is not a function`. I guess it's something that is not in the `0.10.1` release. For a C# `string[]` none of these worked, giving me `Parameter is not a type that be enumerated.` so I had to use standard `for` loop `for (let i = 0; i < arr.length; i++) { console.log(arr.get(i)) }` Thanks.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/qmlnet#130
No description provided.