Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt WebKit
  4. How can i expose an Microsoft web Browser control embed in QAxWidget to javascript ?
Forum Update on Monday, May 27th 2025

How can i expose an Microsoft web Browser control embed in QAxWidget to javascript ?

Scheduled Pinned Locked Moved Qt WebKit
4 Posts 2 Posters 4.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    giselite
    wrote on 28 Oct 2011, 14:34 last edited by
    #1

    Hello,
    I am a new Qt learner ,i need to write some application program use GoogleEarth API in recently , the trick for this work is to load the Earth in a web browser and in the web page's JavaScript call the function of the win form which have been exposed to com object,and vice versa.
    The problem is that when I use QWebView load the html file,the Google earth plug-in post the message that the browser is not support Google Earth plug-in.Because I have successfully make it in VB.NET,C# and MFC,but my boss not allow me to use these approach and force me to use Qt. So the only way I can think out is to use ActiveX control in Qt application.In MFC program i do it like this:
    Use CHtmlView as the base class of a win from and expose win from method to javascript use this micro:

    @
    BEGIN_DISPATCH_MAP(CVirtualEarthView, CHtmlView)
    DISP_FUNCTION(CVirtualEarthView, "winMessage", OnWinMessage, VT_EMPTY, VTS_BSTR)
    ...
    END_DISPATCH_MAP()
    @

    then in javascript i can call win from's method like this: window.external.winMessage("Hello!")
    In c# like this :

    @
    [comvisiable(true)]
    class GeForm
    {
    private System.Windows.Forms.WebBrowser wndWebView;
    public GeForm()
    {
    //...
    this.wndWebView.ObjectForScripting = this;
    }
    //....
    public void Msg(sting)
    {
    MessageBox.Show(msg);
    }
    }
    @

    also call the win from's method in javaScript use
    @
    window.external.Msg("hello")
    ...
    @
    When use QWebView , i can also do it via the QWebFrame's addToJavaScriptWindowObject method
    @
    ui.wndWebView->page()->mainFrame()->addToJavaScriptWindowObject("winForm", this);
    @
    but when i use the ActiveX control of Microsoft web Browser to instead QWebView,i really don't know how to do it ,so is there any one can give me some help?

    [EDIT: code formatting, please wrap in @-tags, Volker]

    1 Reply Last reply
    0
    • L Offline
      L Offline
      lgeyer
      wrote on 28 Oct 2011, 15:52 last edited by
      #2

      Have you tried to stick to WebKit and just fake the user agent?

      1 Reply Last reply
      0
      • G Offline
        G Offline
        giselite
        wrote on 29 Oct 2011, 08:06 last edited by
        #3

        Thank edit,it's really a beautiful presentation of code,thank you for your tip!

        And Lukas can you give me something more detailed? thanks.

        1 Reply Last reply
        0
        • G Offline
          G Offline
          giselite
          wrote on 29 Oct 2011, 14:58 last edited by
          #4

          What about your means "fake the agent"? thanks
          [quote author="Lukas Geyer" date="1319817179"]Have you tried to stick to WebKit and just fake the user agent?[/quote]

          1 Reply Last reply
          0

          1/4

          28 Oct 2011, 14:34

          • Login

          • Login or register to search.
          1 out of 4
          • First post
            1/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved