Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How would i export object to Qml by SetContextProperty ? #229

Open
jaredtao opened this issue Jan 9, 2021 · 0 comments
Open

How would i export object to Qml by SetContextProperty ? #229

jaredtao opened this issue Jan 9, 2021 · 0 comments

Comments

@jaredtao
Copy link

jaredtao commented Jan 9, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant