PDA

View Full Version : Combining QWebView, QWebPage and createWindow (acceptNavigationRequest)



smudo
2nd March 2010, 12:27
i have a simple app containing 3 classes:


MainWindow
Webpage
Webview


The Mainwindow is a simple QT-Form.
WebView is derived from QWebView because i want to create a new window if a user clicks on a button with javascript. The script looks like this:


onclick="window.open('somefile.htm','NewWindow','width=450, height=750')"

Without that, a click on that button does nothing...

The Webview-Class has the following createWindow-Function(opens an empty Webview):


QWebView* Webview::createWindow(QWebPage::WebWindowType type)
{
switch(type)
{
case QWebPage::WebBrowserWindow: // The window is a regular web browser window
QMessageBox::information(NULL, "Type", "WebBrowserWindow:");
break;
case QWebPage::WebModalDialog: // The window acts as modal dialog.
QMessageBox::information(NULL, "Type", "WebModalDialog");
break;
default:
break;
}

return new QWebView(NULL);
}

In my MainWindow i created my QWebView and QWebPage, placed it on the form and load the html content with the buttons via load(). Works so far.



webview = new Webview(ui->centralWidget);
webpage = new Webpage(this);
webview->setPage(webpage);
webview->load(QUrl("file:///c:/Users/flammig-to/Documents/QTWebview/login.html"));
webview->show();


Finally my acceptNavigationRequest-Methos in my webpage-class (which is derived from QWebpage):



bool Webpage::acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &request, NavigationType type)
{
return QWebPage::acceptNavigationRequest(frame,request,ty pe);
}


My problem is:
acceptNavigationRequest is only called at load-Time - but not when i click on the button of my html-page. The NavigationType is QWebPage::NavigationTypeOther. If i click on the button with my onclick-handler a new (of course empty) windows opens.

Maybe someone can help me..
Smudo

oh... i forgot:
i use QT 4.6.1 on XP and Win7

smudo
3rd March 2010, 08:04
ok, i found out: acceptNavigationRequest only gets fired when i hit - for example - the submit-button but not by simply hit a button.
So, a last question: how can i access the url (request) when QWebview calls createWindow?