QWebView, how to handle with JS events?
-
wrote on 27 Aug 2012, 17:11 last edited by
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?! -
wrote on 27 Aug 2012, 18:08 last edited by
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.
-
wrote on 27 Aug 2012, 18:14 last edited by
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*'
@ -
wrote on 27 Aug 2012, 18:24 last edited by
It should be
@
frame->addToJavaScriptWindowObject("sender", this);
@
because you have pointer to QWebFrameWebKit1 is in Qt 4.X and WebKit2 is available in Qt5.X
-
wrote on 27 Aug 2012, 18:34 last edited by
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 )
@ -
wrote on 27 Aug 2012, 19:27 last edited by
Solved!
Just add:@
#include <QWebFrame>
@
3/6