[Qt-interest] addToJavaScriptWindowObject for JS in HTML?

Tony Rietwyk tony.rietwyk at rightsoft.com.au
Mon Oct 12 09:47:22 CEST 2009


Hi Paul, 

If those alerts are in the page itself, it might indicate that the signal is
only received *after* the page is loaded.  So only javascript in events will
see the Qt object.  

Try putting them in a <body onload> handler. 

Hope that helps! 



> -----Original Message-----
> From: qt-interest-bounces at trolltech.com 
> [mailto:qt-interest-bounces at trolltech.com] On Behalf Of Paul Colby
> Sent: Monday, 12 October 2009 17:45
> To: qt-interest
> Subject: [Qt-interest] addToJavaScriptWindowObject for JS in HTML?
> 
> 
> I can't figure this out... there must be something I'm missing.
> 
> I've used QWebFrame::addToJavaScriptWindowObject quite a bit, and find
> it very useful.  But now I'm trying to use it slightly differently,
> but to my surprise I cannot get it to work.
> 
> I have a basic QObject-derived class that implements a single
> read-only Q_PROPERTY called "version".
> 
> So if I expose that object under the name "myObject", then this works:
> 
> QVariant 
> result=webView.page()->mainFrame()->evaluateJavaScript(QString
> ::fromAscii("myObject.version"));
> 
> However, if I load a HTML page that contains the following JavaScript:
> 
> alert(myObject); // null.
> alert(document.getElementById("myObject")); // undefined.
> 
> I get "null" and "undefined" respectively.  Should this be the case?
> 
> I know about QWebFrame::javaScriptWindowObjectCleared - I'm calling
> addToJavaScriptWindowObject there, and in about 20 other places /
> signals just be sure... but that none of them help :(
> 
> Also, I've overridden QWebPage::javaScriptAlert, and there, as the
> "null" and "undefined" messages are coming though, I can see that the
> associated QWebFrame parameter *does* has have my object (ie
> evaluateJavaScript finds it just fine).
> 
> So, am I missing something?  Is HTML-embedded JavaScript meant to be
> able to see objects exposed by addToJavaScriptWindowObject?  or are
> they only meant to be visible to explicit evaluateJavaScript calls?
> 
> Thanks :)
> 
> paul
> -- 
> http://colby.id.au
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
> 
> __________ Information from ESET NOD32 Antivirus, version of 
> virus signature database 4498 (20091011) __________
> 
> The message was checked by ESET NOD32 Antivirus.
> 
> http://www.eset.com
> 
> 
> 





More information about the Qt-interest-old mailing list