我正在尝试制作一个与QT Gui一起运行的简单服务器程序。但是,在应用程序显示后,我不知道如何执行服务器。如果我这样做,GUI就会挂起。
from PyQt5 import QtCore, QtGui, QtWidgets, uic
import socket
import sys
class MyWindow(QtWidgets.QMainWindow):
def __init__(self):
super(MyWindow, self).__init__()
uic.loadUi('tempui.ui', self)
self.show()
def exampleServer():
host = ''
port = 8484
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.bind((host, port))
sock.listen(10)
sock.accept()
# Do stuff
def main():
app = QtWidgets.QApplication(sys.argv)
window = MyWindow()
exampleServer() # It hangs because of this
sys.exit(app.exec_())
if __name__ == '__main__':
main()