本文介绍了QWebView允许弹出窗口吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

在我的项目中,我有一个QWebView,它加载了一个打开弹出窗口的页面.但是窗户不会打开.我调查了createWindow函数,但不知道如何对小部件进行子类化.这些是我在webView上设置的一些设置:

In my project, I have a QWebView that loads a page that opens a pop-up window. But the window won't open. I looked into the createWindow function but I have no clue how to subclass a widget. These are some settings I put onto the webView:

QWebSettings *settings = ui->webView_2->settings();
settings->setAttribute(QWebSettings::JavascriptEnabled, true);
settings->setAttribute(QWebSettings::JavascriptCanOpenWindows, true);

允许我的webView允许弹出窗口的最简单方法是什么?

What is the easiest way to allow my webView to allow pop-up windows?

感谢您的时间:)

推荐答案

您需要重新实现QWebView的 createWindow 方法.返回的QWebView将自动设置为所需的URL.

You need to reimplement QWebView's createWindow method. The QWebView returned will be set to the required URL automatically.

例如:

QWebView* WebView::createWindow(QWebPage::WebWindowType type)
{
    // WindowDialog is just a simple QDialog with a QWebView
    WindowDialog* dlg = new WindowDialog(this);
    dlg->show();

    // A method to retrieve a pointer to the QWebView of the dialog is needed
    return dlg->webView();
}

请记住,cookie不在两个QWebView之间共享,因此您还需要实现自己的cookie管理器.一种方法是继承QNetworkCookieJar,并保留一个静态的全局"实例.

Keep in mind that cookies do not share between the two QWebViews, so you also need to implement your own cookie manager. One way to do it would be to inherit QNetworkCookieJar, and keep a static "global" instance.

这篇关于QWebView允许弹出窗口吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-08 06:04