1

我有一个类似于此的代码:

class A(QWebView):
    def __init__(self):
        # some code here
        # in here I want to check what url is loaded and based on that assign appropriate SLOT
        # I was wondering how to do something like that:
        # if 'examle.html' in self.url():
        #     self.loadFinished.connect(self.example)
        # else:
        #     self.loadFinished.connect(self.anotherSLOT)

if __name__ == '__main__':
    app = QApplication(sys.argv)
    br = A()
    br.load(QUrl('http://example')
    br.show()
    app.exec_()

我有一种感觉,我做的完全错了。理想情况下,我想加载两个 url 并将其连接到适当的插槽,但现在我只想出了这种解决方案。

4

1 回答 1

1

你得到当前的网址:

self.url().toString()

然后你可以检查:

    if 'example' in self.url().toString() \
    or self.url().toString().endswith('example') \ 
    or 'example' in self.url().toString().split("/"):
        pass
于 2012-12-07T01:26:51.283 回答