QWebView, how to handle with JS events?
-
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?! -
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.
-
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*'
@ -
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
-
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 )
@ -
Solved!
Just add:@
#include <QWebFrame>
@