Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QWebView, how to handle with JS events?

QWebView, how to handle with JS events?

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 6.4k 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.
  • D Offline
    D Offline
    dcbasso
    wrote on 27 Aug 2012, 17:11 last edited by
    #1

    It's possible to handle with JS events or make the JavaScript execute some C/C++ codes in Qt?
    I need to make my webpage interact with the local application... Could I do that?!

    1 Reply Last reply
    0
    • G Offline
      G Offline
      guziemic
      wrote on 27 Aug 2012, 18:08 last edited by
      #2

      Hi,

      Yes, it is possible to make own object and to allow interaction with local application.
      If you are going to use WebKit1 then in QWebFrame there is a signal to which you should connect your slot. In this slot you should add your objects that you wish to be visible within web page.

      "QWebFrame":http://doc.qt.nokia.com/4.7-snapshot/qwebframe.html#javaScriptWindowObjectCleared

      In case of WebKit2 I am do not know if similar mechanism exists.

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dcbasso
        wrote on 27 Aug 2012, 18:14 last edited by
        #3

        I don't know which version I'm using...

        I'm trying this code:

        @
        QWebFrame* frame = ui->webView->page()->mainFrame();
        frame.addToJavaScriptWindowObject("sender", this);
        @

        Erro:
        @
        mainwindow.cpp:13:11: error: request for member 'addToJavaScriptWindowObject' in 'frame', which is of non-class type 'QWebFrame*'
        @

        1 Reply Last reply
        0
        • G Offline
          G Offline
          guziemic
          wrote on 27 Aug 2012, 18:24 last edited by
          #4

          It should be
          @
          frame->addToJavaScriptWindowObject("sender", this);
          @
          because you have pointer to QWebFrame

          WebKit1 is in Qt 4.X and WebKit2 is available in Qt5.X

          1 Reply Last reply
          0
          • D Offline
            D Offline
            dcbasso
            wrote on 27 Aug 2012, 18:34 last edited by
            #5

            I'm using Qt 4.7, so Webkit1.

            @
            QWebView* qWebView = ui->webView;
            QWebPage* qWebPage = qWebView->page();
            QWebFrame* qWebFrame = qWebPage->mainFrame();
            @

            I can't access the methods of qWebFrame object!
            And the "QWebFrame" has the method that I want to access:

            @
            void addToJavaScriptWindowObject ( const QString & name, QObject * object )
            @

            1 Reply Last reply
            0
            • D Offline
              D Offline
              dcbasso
              wrote on 27 Aug 2012, 19:27 last edited by
              #6

              Solved!
              Just add:

              @
              #include <QWebFrame>
              @

              1 Reply Last reply
              0

              3/6

              27 Aug 2012, 18:14

              • Login

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