Adding JavaScript Obj to QWebView issues
I am adding html/js to my QWebView like so... and I am also adding my custom object like so... but I can't get the object to do anything inside of the javascript.
Code:
uiDemo.webView->setHtml(sCode.toUtf8());
uiDemo.webView->page()->mainFrame()->addToJavaScriptWindowObject("QtJSObject", m_pJSObj);
Code:
// The javascript code that doesn't run
window.alert('QtJSObject.var is:' + QtJSObject.var)
// My object properites
Q_PROPERTY(int var READ getVar WRITE setVar);
When I ask for the value of "var" from the properties method in C++ it returns fine... just not in my script. Am I adding the JavaScript Object to my QWebView correctly?
Re: Adding JavaScript Obj to QWebView issues
Here is an update. I am capturing the javaScriptWindowObjectCleared () signal and injecting my objects that way now. I can run all of my slot/js functions just fine... so I am excited. My properties are not working though.
QtJSObject.var is not returning getVar() when I call it from javascript.
If anyone has any ideas... let me know. If I figure it out I will post back.
I am going to submit my demo when I get it done... hopefully it will help people.
Re: Adding JavaScript Obj to QWebView issues
Ok... I've learned something today. When you set your Q_PROPERTY... make sure the variable name is exactly like one you have declaired in your class. Also... don't name it "var". It stopped working when I did that and I had to name it to something else... like "Var". :p