PDA

View Full Version : Adding JavaScript Obj to QWebView issues



bpetty
13th May 2008, 17:25
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.



uiDemo.webView->setHtml(sCode.toUtf8());
uiDemo.webView->page()->mainFrame()->addToJavaScriptWindowObject("QtJSObject", m_pJSObj);




// 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?

bpetty
13th May 2008, 19:35
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.

bpetty
13th May 2008, 21:44
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