I use the following mechanism to handle clicking links in the browser:

browser->page()->setLinkDelegationPolicy(QWebPage::LinkDelegationPolicy::DelegateAllLinks); QObject::connect(browser, &QWebView::linkClicked, this, [urlHandler](const QUrl& url) { urlHandler(url); }); 

Thus, all links on the page are processed. But I need to intercept only certain links, for the rest I have a JS script defined, which should be executed.

Is it possible to make this behavior by standard means or is it necessary to change the source code of Qt?

Qt version used is 5.5

    1 answer 1

    I did not find the standard means of implementation, so I went around the line.

    The necessary links for processing should be made in a special way: for example, add a prefix before the main url-address. When receiving a signal, check the presence of the prefix. If you need to continue loading, you can use the load function (example):

     QObject::connect(browser, &QWebView::linkClicked, this, [=](const QUrl& url) { if (hasPrefix(url)) { urlHandler(url); } else { browser->load(url); } }); 

    There is also a linkHovered signal in the QWebPage class, with which you can get the title, address and text of the link.