[GH-ISSUE #218] How to pass a list to C#? #140

Closed
opened 2026-05-05 11:06:37 -06:00 by gitea-mirror · 1 comment
Owner

Originally created by @vadi2 on GitHub (Aug 16, 2020).
Original GitHub issue: https://github.com/qmlnet/qmlnet/issues/218

I need to pass a list of urls from QML to a C# method.

So far I've tried List<string> as the parameter signature on the C# side and converted all of the urls to strings in QML, which does seem to create a parameter on the C#, but that list is empty as far as it's concerned.

                    FileDialog {
                        id: resourcePicker
                        onAccepted: {console.log(convertUriToString(resourcePicker.files)); appmodel.loadResourceFile(convertUriToString(resourcePicker.files))}
                        fileMode: FileDialog.OpenFiles

                        function convertUriToString(files) {
                            var stringFiles = [];
                            for (var i  = 0; i < files.length; i++) {
                                stringFiles.push(files[i].toString());
                            }

                            return stringFiles;
                        }
                    }
public bool LoadResourceFile (List<string> files) {
Originally created by @vadi2 on GitHub (Aug 16, 2020). Original GitHub issue: https://github.com/qmlnet/qmlnet/issues/218 I need to pass a list of `url`s from QML to a C# method. So far I've tried `List<string>` as the parameter signature on the C# side and converted all of the `url`s to `string`s in QML, which does seem to create a parameter on the C#, but that list is empty as far as it's concerned. ```js FileDialog { id: resourcePicker onAccepted: {console.log(convertUriToString(resourcePicker.files)); appmodel.loadResourceFile(convertUriToString(resourcePicker.files))} fileMode: FileDialog.OpenFiles function convertUriToString(files) { var stringFiles = []; for (var i = 0; i < files.length; i++) { stringFiles.push(files[i].toString()); } return stringFiles; } } ``` ```csharp public bool LoadResourceFile (List<string> files) { ```
Author
Owner

@pauldotknopf commented on GitHub (Aug 16, 2020):

Pass the array to C# as a INetJsValue, then use AsList<T>() to convert that javascript value to a list.

There is plans to eventually make this more seamless.

845913eb3b/src/net/Qml.Net/Extensions/INetJsValueExtensions.cs (L9)

<!-- gh-comment-id:674558505 --> @pauldotknopf commented on GitHub (Aug 16, 2020): Pass the array to C# as a ```INetJsValue```, then use ```AsList<T>()``` to convert that javascript value to a list. There is plans to eventually make this more seamless. https://github.com/qmlnet/qmlnet/blob/845913eb3b14887879888cec0e7d0c914c21a30c/src/net/Qml.Net/Extensions/INetJsValueExtensions.cs#L9
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#140
No description provided.