[GH-ISSUE #229] How would i export object to Qml by SetContextProperty ? #146

Open
opened 2026-05-05 11:06:44 -06:00 by gitea-mirror · 0 comments
Owner

Originally created by @jaredtao on GitHub (Jan 9, 2021).
Original GitHub issue: https://github.com/qmlnet/qmlnet/issues/229

question

I want to export object to Qml by SetContextProperty, but qml report error on console:

   xxx.qml:  TypeError: Cannot read property 'transString' of null

detail

I have a class declare like this:

 public class Trans 
 {
        [NotifySignal("currentLangChanged")]
        public string currentLang { get; set; } = "English";

        [NotifySignal("transStringChanged")]
        public string transString { get; set; } = "";

        [NotifySignal("languagesChanged")]
        public List<string> languages { get; set; }
        
        ....

        public void loadFolder(string folder) 
        {  ....   }
 }

I want to call loadFolder in c# not qml, so i use SetContextProperty in main function

        static int Main(string[] args)
        {
             ...
             var trans = new Trans();
             trans.loadFolder(Config.Config.transPath);
             engine.SetContextProperty("trans", trans);
             .....
        }

source code

https://github.com/jaredtao/TaoQuick.Net

Originally created by @jaredtao on GitHub (Jan 9, 2021). Original GitHub issue: https://github.com/qmlnet/qmlnet/issues/229 > question I want to export object to Qml by SetContextProperty, but qml report error on console: ``` xxx.qml: TypeError: Cannot read property 'transString' of null ``` > detail I have a class declare like this: ```c# public class Trans { [NotifySignal("currentLangChanged")] public string currentLang { get; set; } = "English"; [NotifySignal("transStringChanged")] public string transString { get; set; } = ""; [NotifySignal("languagesChanged")] public List<string> languages { get; set; } .... public void loadFolder(string folder) { .... } } ``` I want to call loadFolder in c# not qml, so i use SetContextProperty in main function ```c# static int Main(string[] args) { ... var trans = new Trans(); trans.loadFolder(Config.Config.transPath); engine.SetContextProperty("trans", trans); ..... } ``` > source code https://github.com/jaredtao/TaoQuick.Net
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#146
No description provided.