Вопрос

i have flash player running on QWebkit , and on the flash player there are some web links that needs to be open in external browser , what i did is :

m_webView->page()->setLinkDelegationPolicy(QWebPage::LinkDelegationPolicy::DelegateAllLinks);
    connect(m_webView->page(),SIGNAL(linkClicked(const QUrl&)),
                            this,
                            SLOT(linkClickedHandler(const QUrl&)),Qt::DirectConnection); 


void WebBroswerDeleget::linkClickedHandler(const QUrl& url)
{
QDesktopServices::openUrl(QUrl(url.toString(), QUrl::TolerantMode));
}

but its never triggered even of i change in the connect from m_webView->page() to m_webView

Это было полезно?

Решение

i overrided the QWebview::createWindow like this:

QWebView* MyAdWebview::createWindow (QWebPage::WebWindowType type)
{
    QWebView* p = new QWebView(0);
    connect(p->page()->networkAccessManager(), SIGNAL(finished(QNetworkReply*)), this, SLOT(newWindowLoadFinished(QNetworkReply*)), Qt::UniqueConnection);
    return p;
}

void MyAdWebview::newWindowLoadFinished(QNetworkReply* reply) {
    QDesktopServices::openUrl(reply->url().toString());
}

QDesktopServices::openUrl is a cutom function which opens the default system browser with this url

Другие советы

This is working for me on both 4.7.2 QtEmbedded and 4.8.1 on mac. What I don't understand is this:

m_webView->page()->setLinkDelegationPolicy(QWebPage::LinkDelegationPolicy::DelegateAllLinks);

Just do:

m_webView->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);

Something like this works for me:

#include <QWebPage>
#include <QWebView>
#include <QApplication>
#include "sigrec.h"

int main(int argc, char** argv)
{
    QApplication a(argc, argv);

    SigRec rec;

    QWebView view;
    view.page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
    QObject::connect(view.page(), SIGNAL(linkClicked(const QUrl&)), &rec, SLOT(onLinkClicked(const QUrl&)),
                     Qt::DirectConnection);
    view.show();
    view.setUrl(QUrl("http://www.google.com"));

    return a.exec();
}

Where SigRec is something like this:

#ifndef SIGREC_H
#define SIGREC_H

#include <QObject>
#include <QUrl>

class SigRec : public QObject
{
    Q_OBJECT
public:
    explicit SigRec(QObject *parent = 0);

public slots:
    void onLinkClicked(const QUrl &url);
};

#endif // SIGREC_H
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top