0
我是python線程和Pyside的新手。我的工作是使兩臺計算機之間的通信,但不能接收側 這裏創建一個線程是服務器代碼QObject:無法爲不同線程的父項創建子項.Parent爲QTextDocument,父線程爲QThread,當前線程爲QThread
from PySide import QtCore, QtGui
import sys
import receiver
import os
from socket import *
import thread
class mainWindow(QtGui.QMainWindow, receiver.Ui_MainWindow):
def __init__(self):
super(self.__class__,self).__init__()
self.setupUi(self)
self.show()
thread.start_new_thread(self.listener,())
def listener(self):
host = ""
port = 13000
buf = 1024
addr = (host, port)
UDPSock = socket(AF_INET, SOCK_DGRAM)
UDPSock.bind(addr)
(data, addr) = UDPSock.recvfrom(buf)
self.textEdit.setText(data)
UDPSock.close()
def main():
app = QtGui.QApplication(sys.argv)
mainWin = mainWindow()
mainWin.show()
app.exec_()
if __name__ == "__main__":
main()
當我從客戶端,程序崩潰時發送的任何消息。
線程在客戶端完美運行。 這是客戶端代碼
from PySide import QtCore, QtGui
import sys
import main
import os
from socket import *
import thread
class mainWindow(QtGui.QMainWindow, main.Ui_MainWindow):
def __init__(self):
super(self.__class__,self).__init__()
self.setupUi(self)
self.show()
self.sendButton.clicked.connect(self.clientProcess)
def clientProcess(self):
thread.start_new_thread(self.makeClient,())
def makeClient(self):
host = "192.168.43.143"
port = 13000
addr = (host, port)
UDPSock = socket(AF_INET, SOCK_DGRAM)
data = "Successfully Completed"
UDPSock.sendto(data, addr)
UDPSock.close()
def main():
app = QtGui.QApplication(sys.argv)
mainWin = mainWindow()
mainWin.show()
app.exec_()
if __name__ == "__main__":
main()
我在做什麼錯?