QTextBrowser に HTML コンテンツを表示する簡単なブラウザ プログラムを作成しました。そのhtmlコンテンツにはハイパーリンクがあり、ハイパーリンクで別のページを開く(サーバーから受信したhtmlコンテンツを表示する)必要があります。基本的に、ユーザーが URL ボックスに「サーバー」と入力した後、サーバーはクライアント (ブラウザー) に HTML データを送信し、それが QTextBrowser に表示された後、ユーザーはリンクをクリックできます。リンクをクリックした後、クライアントは別のページを要求します。次に、サーバーは html データを送信してこの要求を満たし、ブラウザは html コンテンツを再度表示する必要があります。私のコードの問題は、すべての機能が正しく動作しているにもかかわらず、2 番目の要求の後に html データが表示されないことです。何が問題なのですか?
class Browser(QtGui.QMainWindow):
def __init__(self):
super(Browser, self).__init__()
self.ui = uic.loadUi('gui_browser.ui')
self.csi_thread = Client_Server_Interactive_Thread()
self.connect(self.csi_thread, QtCore.SIGNAL("display_html(QString)"), self.display_html)
self.ui.txt_browser.setOpenExternalLinks(True)
self.connect(self.ui.txt_browser,
QtCore.SIGNAL('anchorClicked(const QUrl &)'),
self.anchorClickedHandler)
def anchorClickedHandler(self):
self.ui.txt_browser.setSource(QtCore.QUrl("html_file.html"))
send_msg('link') # sends the server a request
def display_html(self, data):
temp_html_file = open('html_file.html', 'w')
temp_html_file.write(data)
temp_html_file.close()
self.ui.txt_browser.setText(data)
self.parse_document(data)
class Client_Server_Interactive_Thread(QtCore.QThread):
def __init__(self):
super().__init__()
def run(self):
socket_create()
while True:
msg = listen_for_msg()
self.emit(QtCore.SIGNAL('display_html(QString)'), msg)