[GH-ISSUE #129] How to access QML object in .NET? #77

Closed
opened 2026-05-05 11:03:38 -06:00 by gitea-mirror · 4 comments
Owner

Originally created by @vadi2 on GitHub (Apr 26, 2019).
Original GitHub issue: https://github.com/qmlnet/qmlnet/issues/129

I'd like to change the label of a Groupbox in QML using .NET - what is the right way to do this? I see that https://github.com/qmlnet/qmlnet/pull/122 has went in recently but not sure if it's related / how to use it.

Originally created by @vadi2 on GitHub (Apr 26, 2019). Original GitHub issue: https://github.com/qmlnet/qmlnet/issues/129 I'd like to change the label of a Groupbox in QML using .NET - what is the right way to do this? I see that https://github.com/qmlnet/qmlnet/pull/122 has went in recently but not sure if it's related / how to use it.
Author
Owner

@pauldotknopf commented on GitHub (Apr 26, 2019):

The issue you referenced is unrelated.

You'd want to do something like this:

NetType {
    id: netType
}
GroupBox {
    title: netType.groupBoxTitle
}
public class NetType
{
    private string _groupBoxTitle;

    [NotifySignal]
    public string GroupBoxTitle
    {
        get => _groupBoxTitle;
        set
        {
            if (_groupBoxTitle == value)
            {
                return;
            }
            _groupBoxTitle = value;
            this.ActivateProperty(x => x.GroupBoxTitle);
        }
    }
}
<!-- gh-comment-id:487057412 --> @pauldotknopf commented on GitHub (Apr 26, 2019): The issue you referenced is unrelated. You'd want to do something like this: ```qml NetType { id: netType } GroupBox { title: netType.groupBoxTitle } ``` ```c# public class NetType { private string _groupBoxTitle; [NotifySignal] public string GroupBoxTitle { get => _groupBoxTitle; set { if (_groupBoxTitle == value) { return; } _groupBoxTitle = value; this.ActivateProperty(x => x.GroupBoxTitle); } } } ```
Author
Owner

@vadi2 commented on GitHub (May 1, 2019):

Thanks, that works! And... simple question, how can I work with this class from within .NET? I need an object to reference. I looked at the qml-examples but could not find a solution.

<!-- gh-comment-id:488215267 --> @vadi2 commented on GitHub (May 1, 2019): Thanks, that works! And... simple question, how can I work with this class from within .NET? I need an object to reference. I looked at the qml-examples but could not find a solution.
Author
Owner

@vadi2 commented on GitHub (May 1, 2019):

I see from the docs that RegisterType() instantiates it, so I guess I need some way to get a reference to that.

<!-- gh-comment-id:488216211 --> @vadi2 commented on GitHub (May 1, 2019): I see from the docs that `RegisterType()` instantiates it, so I guess I need some way to get a reference to that.
Author
Owner

@vadi2 commented on GitHub (May 4, 2019):

Got it sorted! Using it from the same class seems to be fine.

<!-- gh-comment-id:489298677 --> @vadi2 commented on GitHub (May 4, 2019): Got it sorted! Using it from the same class seems to be fine.
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#77
No description provided.