There's nothing wrong with webkit. Your code was not displaying a new view (i.e. never called show()). Here is a working example with the new windows logic in the view not page.
#include <QtGui>
#include <QWebPage>
#include <QWebView>
#include <QDebug>
class WebView: public QWebView
{
Q_OBJECT
public:
WebView
(QWidget *p
= 0): QWebView
(p
) {
}
QWebView *createWindow(QWebPage::WebWindowType type)
{
QWebView *webView = new QWebView;
QWebPage *newWeb = new QWebPage(webView);
if (type == QWebPage::WebModalDialog)
webView->setWindowModality(Qt::ApplicationModal);
webView->setAttribute(Qt::WA_DeleteOnClose, true);
webView->setPage(newWeb);
webView->show();
return webView;
}
};
int main(int argc, char *argv[])
{
WebView view;
view.settings()->setAttribute(QWebSettings::JavascriptEnabled, true);
view.settings()->setAttribute(QWebSettings::JavascriptCanOpenWindows, true);
QUrl url
= QUrl::fromLocalFile("/tmp/tt/test.html");
view.load(url);
view.show();
return a.exec();
}
#include "main.moc"
#include <QtGui>
#include <QWebPage>
#include <QWebView>
#include <QDebug>
class WebView: public QWebView
{
Q_OBJECT
public:
WebView(QWidget *p = 0): QWebView(p)
{
}
QWebView *createWindow(QWebPage::WebWindowType type)
{
QWebView *webView = new QWebView;
QWebPage *newWeb = new QWebPage(webView);
if (type == QWebPage::WebModalDialog)
webView->setWindowModality(Qt::ApplicationModal);
webView->setAttribute(Qt::WA_DeleteOnClose, true);
webView->setPage(newWeb);
webView->show();
return webView;
}
};
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
WebView view;
view.settings()->setAttribute(QWebSettings::JavascriptEnabled, true);
view.settings()->setAttribute(QWebSettings::JavascriptCanOpenWindows, true);
QUrl url = QUrl::fromLocalFile("/tmp/tt/test.html");
view.load(url);
view.show();
return a.exec();
}
#include "main.moc"
To copy to clipboard, switch view to plain text mode
Bookmarks