Results 1 to 3 of 3

Thread: Adding JavaScript Obj to QWebView issues

  1. #1
    Join Date
    Aug 2006
    Posts
    90
    Thanks
    6
    Thanked 4 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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.

    Qt Code:
    1. uiDemo.webView->setHtml(sCode.toUtf8());
    2. uiDemo.webView->page()->mainFrame()->addToJavaScriptWindowObject("QtJSObject", m_pJSObj);
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. // The javascript code that doesn't run
    2. window.alert('QtJSObject.var is:' + QtJSObject.var)
    3.  
    4. // My object properites
    5. Q_PROPERTY(int var READ getVar WRITE setVar);
    To copy to clipboard, switch view to plain text mode 

    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?

  2. #2
    Join Date
    Aug 2006
    Posts
    90
    Thanks
    6
    Thanked 4 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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.

  3. #3
    Join Date
    Aug 2006
    Posts
    90
    Thanks
    6
    Thanked 4 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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".

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.