[GH-ISSUE #235] Getting C# reference to RegisterSingletonType instance #152

Closed
opened 2026-05-05 11:06:51 -06:00 by gitea-mirror · 2 comments
Owner

Originally created by @YTN0 on GitHub (Apr 27, 2021).
Original GitHub issue: https://github.com/qmlnet/qmlnet/issues/235

I am new to qt / qml and have started experimenting with using qml.net. So far it's been working really well. I have not been able to figure out how to get the reference to a singleton instance in my c# code. I have used the RegisterSingletonType method which works fine, and I can use the singleton instance in the qml code without issues.

However, I need to reference the same singleton instance from c# to update some data. Can someone please clarify how this can be done?

Thanks.

Originally created by @YTN0 on GitHub (Apr 27, 2021). Original GitHub issue: https://github.com/qmlnet/qmlnet/issues/235 I am new to qt / qml and have started experimenting with using qml.net. So far it's been working really well. I have not been able to figure out how to get the reference to a singleton instance in my c# code. I have used the RegisterSingletonType method which works fine, and I can use the singleton instance in the qml code without issues. However, I need to reference the same singleton instance from c# to update some data. Can someone please clarify how this can be done? Thanks.
Author
Owner

@pauldotknopf commented on GitHub (Apr 27, 2021):

I'm not sure there is a way.

I guess you can update the ctor of your .NET type, to put this into a static variable that can be accessed elsewhere?

<!-- gh-comment-id:827616829 --> @pauldotknopf commented on GitHub (Apr 27, 2021): I'm not sure there is a way. I guess you can update the ```ctor``` of your .NET type, to put ```this``` into a static variable that can be accessed elsewhere?
Author
Owner

@YTN0 commented on GitHub (May 16, 2021):

Thanks for the response. I managed to find a solution for this.

<!-- gh-comment-id:841763324 --> @YTN0 commented on GitHub (May 16, 2021): Thanks for the response. I managed to find a solution for this.
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#152
No description provided.