久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

  • <tfoot id='f5Xr8'></tfoot>

    <small id='f5Xr8'></small><noframes id='f5Xr8'>

      <i id='f5Xr8'><tr id='f5Xr8'><dt id='f5Xr8'><q id='f5Xr8'><span id='f5Xr8'><b id='f5Xr8'><form id='f5Xr8'><ins id='f5Xr8'></ins><ul id='f5Xr8'></ul><sub id='f5Xr8'></sub></form><legend id='f5Xr8'></legend><bdo id='f5Xr8'><pre id='f5Xr8'><center id='f5Xr8'></center></pre></bdo></b><th id='f5Xr8'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='f5Xr8'><tfoot id='f5Xr8'></tfoot><dl id='f5Xr8'><fieldset id='f5Xr8'></fieldset></dl></div>
        <bdo id='f5Xr8'></bdo><ul id='f5Xr8'></ul>

        <legend id='f5Xr8'><style id='f5Xr8'><dir id='f5Xr8'><q id='f5Xr8'></q></dir></style></legend>

        如何編寫一個(gè)無限循環(huán)來接收UDP數(shù)據(jù)?

        How to write an infinite loop for receiving UDP data?(如何編寫一個(gè)無限循環(huán)來接收UDP數(shù)據(jù)?)

          <legend id='VnIdr'><style id='VnIdr'><dir id='VnIdr'><q id='VnIdr'></q></dir></style></legend>
          <tfoot id='VnIdr'></tfoot>
          <i id='VnIdr'><tr id='VnIdr'><dt id='VnIdr'><q id='VnIdr'><span id='VnIdr'><b id='VnIdr'><form id='VnIdr'><ins id='VnIdr'></ins><ul id='VnIdr'></ul><sub id='VnIdr'></sub></form><legend id='VnIdr'></legend><bdo id='VnIdr'><pre id='VnIdr'><center id='VnIdr'></center></pre></bdo></b><th id='VnIdr'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='VnIdr'><tfoot id='VnIdr'></tfoot><dl id='VnIdr'><fieldset id='VnIdr'></fieldset></dl></div>

              <bdo id='VnIdr'></bdo><ul id='VnIdr'></ul>

                <tbody id='VnIdr'></tbody>

              <small id='VnIdr'></small><noframes id='VnIdr'>

                  本文介紹了如何編寫一個(gè)無限循環(huán)來接收UDP數(shù)據(jù)?的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  我正在嘗試制作一個(gè)接收 UDP 數(shù)據(jù)并使用 python (PyQt5) 在列表視圖中顯示數(shù)據(jù)的應(yīng)用程序.當(dāng)我啟動(dòng)接收器時(shí),應(yīng)用程序卡住并且沒有響應(yīng).我怎樣才能解決這個(gè)問題?請參閱下面的代碼.

                  I'm trying to make an app that receives UDP data and shows the data in a list view using python (PyQt5). When I start the receiver, the app gets stuck and does not respond. How can I fix this? See code below.

                  import sys
                  import os
                  import socket
                  from PyQt5.QtGui import *
                  from PyQt5.QtWidgets import *
                  
                  class udpReceiverApp():
                       app = QApplication (sys.argv)
                       x = 1
                       ip = "192.168.1.4"
                       port =515
                       server_start = True
                       sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
                       sock.bind((ip,port))
                  
                       def __init__(self):
                           self.w = QWidget()
                           self.lbl = QLabel ("udp receiver",self.w)
                           self.btn = QPushButton ("click me",self.w)
                           self.lst = QListWidget(self.w)
                           self.lst.resize(200,100)
                  
                           self.lbl.move(10, 90)
                           self.btn.move(50, 50)
                           self.lst.move(10, 90)
                  
                           self.btn.clicked.connect(self.startReceiver)
                  
                           self.w.setGeometry(300, 300, 300, 200)
                           self.w.setWindowTitle("udp receive")
                           self.w.show()
                           sys.exit(udpReceiverApp.app.exec_())
                  
                       def addLstItem(self):
                           self.lst.insertItem(0,"item"+str(udpReceiverApp.x) )
                           udpReceiverApp.x +=1
                  
                       def startReceiver(self):
                  
                           while udpReceiverApp.server_start:
                                 data, addr = self.sock.recvfrom(1024)
                                 self.lst.insertItem(0,data)
                  
                  udpReceiverApp()
                  

                  推薦答案

                  你不應(yīng)該在主線程中有無限循環(huán),因?yàn)樗鼤?huì)鎖定 Qt 事件循環(huán),而應(yīng)該在另一個(gè)線程中執(zhí)行它并通過信號發(fā)送信息

                  You should not have an infinite loop in the main thread since it locks the Qt event loop, instead you should execute it in another thread and send the information through signals

                  import sys
                  import os
                  import socket
                  from PyQt5 import QtCore, QtWidgets
                  
                  class UDPWorker(QtCore.QObject):
                      dataChanged = QtCore.pyqtSignal(str)
                  
                      def __init__(self, parent=None):
                          super(UDPWorker, self).__init__(parent)
                          self.server_start = False
                  
                      @QtCore.pyqtSlot()
                      def start(self):
                          self.server_start = True
                          ip = "192.168.1.4"
                          port = 515
                          self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
                          self.sock.bind((ip,port))
                          self.process()
                  
                      def process(self):
                          while self.server_start:
                              data, addr = self.sock.recvfrom(1024)
                              self.dataChanged.emit(str(data))
                  
                  class UDPWidget(QtWidgets.QWidget):
                      started = QtCore.pyqtSignal()
                  
                      def __init__(self, parent=None):
                          super(UDPWidget, self).__init__(parent)
                          btn = QtWidgets.QPushButton("Click Me")
                          btn.clicked.connect(self.started)
                          self.lst = QtWidgets.QListWidget()
                  
                          lay = QtWidgets.QVBoxLayout(self)
                          lay.addWidget(QtWidgets.QLabel("udp receiver"))
                          lay.addWidget(btn)
                          lay.addWidget(self.lst)
                  
                          self.setWindowTitle("udp receive")
                  
                      @QtCore.pyqtSlot(str)
                      def addItem(self, text):
                          self.lst.insertItem(0, text)
                  
                  if __name__ == '__main__':
                      import sys
                      app = QtWidgets.QApplication(sys.argv)
                      w = UDPWidget()
                      worker = UDPWorker()
                      thread = QtCore.QThread()
                      thread.start()
                      worker.moveToThread(thread)
                      w.started.connect(worker.start)
                      worker.dataChanged.connect(w.addItem)
                      w.show()
                      sys.exit(app.exec_())
                  

                  這篇關(guān)于如何編寫一個(gè)無限循環(huán)來接收UDP數(shù)據(jù)?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  How to bind a function to an Action from Qt menubar?(如何將函數(shù)綁定到 Qt 菜單欄中的操作?)
                  PyQt progress jumps to 100% after it starts(PyQt 啟動(dòng)后進(jìn)度躍升至 100%)
                  How to set yaxis tick label in a fixed position so that when i scroll left or right the yaxis tick label should be visible?(如何將 yaxis 刻度標(biāo)簽設(shè)置在固定位置,以便當(dāng)我向左或向右滾動(dòng)時(shí),yaxis 刻度標(biāo)簽應(yīng)該可見
                  `QImage` constructor has unknown keyword `data`(`QImage` 構(gòu)造函數(shù)有未知關(guān)鍵字 `data`)
                  Change x-axis ticks to custom strings(將 x 軸刻度更改為自定義字符串)
                  How to show progress bar while saving file to excel in python?(如何在python中將文件保存為excel時(shí)顯示進(jìn)度條?)
                      <bdo id='EdBPF'></bdo><ul id='EdBPF'></ul>
                      • <tfoot id='EdBPF'></tfoot>

                          1. <small id='EdBPF'></small><noframes id='EdBPF'>

                          2. <i id='EdBPF'><tr id='EdBPF'><dt id='EdBPF'><q id='EdBPF'><span id='EdBPF'><b id='EdBPF'><form id='EdBPF'><ins id='EdBPF'></ins><ul id='EdBPF'></ul><sub id='EdBPF'></sub></form><legend id='EdBPF'></legend><bdo id='EdBPF'><pre id='EdBPF'><center id='EdBPF'></center></pre></bdo></b><th id='EdBPF'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='EdBPF'><tfoot id='EdBPF'></tfoot><dl id='EdBPF'><fieldset id='EdBPF'></fieldset></dl></div>
                          3. <legend id='EdBPF'><style id='EdBPF'><dir id='EdBPF'><q id='EdBPF'></q></dir></style></legend>
                              <tbody id='EdBPF'></tbody>

                          4. 主站蜘蛛池模板: 国产免费一区 | www.超碰| 制服丝袜av在线 | 国产免费久久 | 免费在线观看av网站 | 亚洲视频中文字幕 | 国产免费成人 | www.青青草.com | 日韩欧美在线观看 | 亚洲激情欧美激情 | 一区二区三区免费 | 亚洲女优在线 | 午夜www| 亚洲一区二区久久 | 国产精品亚洲精品 | 日本一级淫片 | 91精品国产乱码久久久 | 日韩在线观看一区 | 欧美成人一级 | 亚洲精品综合 | 国产黄色一级片 | 久久精品中文 | 国产亚洲欧美在线 | 国产一及片 | 久久久黄色片 | 日韩成人免费 | 欧美视频在线观看一区 | 国产精品久久久久久久久久久久午夜片 | 人人爽人人爽人人爽 | 日韩一区二区在线视频 | 黄视频免费看网站 | 亚洲一区欧美 | 黄色激情网站 | 国产三级在线免费观看 | 性高潮久久久久久久 | 日韩在线中文字幕 | 男女无遮挡xx00动态图120秒 | 日韩特黄 | 日韩www | 亚洲人天堂 | 亚洲 欧美 另类 综合 偷拍 |