Why does the "linkClicked (const QUrl &)" signal not capture QUrl for the left mouse button?

Firstly, I would like to make it clear that this strange behavior does not apply to every website.

Here is the code from my web browser :

def compose_tab(self, index):
    self.tabs[index].append(QtWebKit.QWebView())
    self.tabs[index][0].setLayout(self.tabs[index][1])
    self.tabs[index][1].addWidget(self.tabs[index][2])
    self.tabs[index][2].connect(self.tabs[index][2], QtCore.SIGNAL("linkClicked(const QUrl&)"), self.update_link)
    # to be written...
    self.tabs[index][2].connect(self.tabs[index][2], QtCore.SIGNAL("OPEN_IN_NEW_TAB"), lambda: [
        # self.add_tab(len(self.tabs)-1),
        None,
        None
    ])
    self.tabs[index][2].load(QtCore.QUrl("http://www.google.com"))
    self.url_field.setText("http://www.google.com")
    self.tabs[index][2].page().setLinkDelegationPolicy(QtWebKit.QWebPage.DelegateAllLinks)
    self.tabs[self.tab_stack.currentIndex()][2].loadProgress.connect(lambda: self.tab_stack.setTabText(
        self.tab_stack.currentIndex(), 
        "Loading..."
    ))
    try:
        self.tabs[self.tab_stack.currentIndex()][2].loadFinished.connect(lambda: self.tab_stack.setTabText(
            self.tab_stack.currentIndex(), 
            self.tabs[self.tab_stack.currentIndex()][2].page().mainFrame().findFirstElement("title").toPlainText()
        ))
    except NameError as e:
        pass
    self.current_links.insert(index, self.url_field.text())
    self.tabs[index][2].show()

As you can see, on each tab there is a QWebView associated with the update_link method, which is as follows:

def update_link(self, url):
    self.url_field.setText(url.toString())
    self.current_links[self.tab_stack.currentIndex()] = url.toString()
    self.tabs[self.tab_stack.currentIndex()][2].load(url)

Thus, each time a link is clicked, the URL field is updated using QUrl, which is passed to the method. It works great on websites like wikipedia, but it works poorly on YouTube (for example). As you can read from the documents , the signal may not come out if Javascript is involved. This is "normal", but there is a problem:

, ( !).

, YouTube , URL- , QUrl update_link, , URL . , "" .

- ? ( ).

EDIT:

urlChanged QUrl YouTube. loadFinished .

+3
1

, , , , . QWebView URL- ( JavaScript), .

, QWebView urlChanged. , URL , URL, :

webview.urlChanged.connect(<custom slot function>)

QUrl, URL- , :

def url_changed(self, q):
   <your-urlbar-obj>.setText(q.toString())
+2

All Articles