Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/345.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
带多线程的Python QT5_Python_Multithreading_Telnetlib - Fatal编程技术网

带多线程的Python QT5

带多线程的Python QT5,python,multithreading,telnetlib,Python,Multithreading,Telnetlib,亲爱的, 我是python新手,尝试用一个简单的代码启动python网络,该代码有2个纯文本行编辑,尝试启动2个telnet会话,并在一个单独的纯文本行区域上获得每个会话的输出,但是我得到了以下错误 QObject::connect:无法对“QTextCursor”类型的参数排队 (确保使用qRegisterMetaType()注册了“QTextCursor”。) 代码如下: app = QApplication(sys.argv) def to_str(bytes_or_str):

亲爱的, 我是python新手,尝试用一个简单的代码启动python网络,该代码有2个纯文本行编辑,尝试启动2个telnet会话,并在一个单独的纯文本行区域上获得每个会话的输出,但是我得到了以下错误

QObject::connect:无法对“QTextCursor”类型的参数排队 (确保使用qRegisterMetaType()注册了“QTextCursor”。)

代码如下:

app = QApplication(sys.argv)

def to_str(bytes_or_str):
    if isinstance(bytes_or_str, bytes):
          value = bytes_or_str.decode() # uses 'utf-8' for encoding
    else:
        value = bytes_or_str
    return value # Instance of str

def testTelnet_start():  # called when button pressed
    _thread.start_new_thread(testTelnet,("192.168.3.247",1))

    print("Test")

    _thread.start_new_thread(testTelnet,("192.168.3.252",2))

def testTelnet(ip,x):
    try:
        tel_conn = telnetlib.Telnet()
        tel_conn.open(host= ip)
        data = tel_conn.read_until(b"login:",3)
        data = to_str(data)
        data = ip + "\n" + data
        print(data)
        if(x==1):
            plain_text_area_Upgrade1.appendPlainText(data)
        elif(x==2):
            plain_text_area_Upgrade2.appendPlainText(data)

    except Exception as e:
        print(e)

my_Test_Window = QWidget()
my_Test_Window.setWindowTitle("Telnet Window")
my_Test_Window.resize(490,350)
my_Test_Window.setFixedSize(my_Test_Window.size())

push_test1 = QPushButton("Test#1",my_Test_Window)
push_test1.move(90,280)

plain_text_area_Upgrade1 = QPlainTextEdit(my_Test_Window)
plain_text_area_Upgrade1.resize(160,150)
plain_text_area_Upgrade1.updatesEnabled()
plain_text_area_Upgrade1.move(25,20)
plain_text_area_Upgrade1.setReadOnly(True)
plain_text_area_Upgrade1.insertPlainText("Testing ...")
plain_text_area_Upgrade1.appendPlainText("")

plain_text_area_Upgrade2 = QPlainTextEdit(my_Test_Window)
plain_text_area_Upgrade2.resize(160,150)
plain_text_area_Upgrade2.updatesEnabled()
plain_text_area_Upgrade2.move(250,20)
plain_text_area_Upgrade2.setReadOnly(True)
plain_text_area_Upgrade2.insertPlainText("Testing ...")
plain_text_area_Upgrade2.appendPlainText("")

push_test1.clicked.connect(testTelnet_start)

my_Test_Window.show()
app.exec_()
知道为什么一个简单的多线程代码会导致这些错误吗


谢谢

Qt和PyQt的基本规则,只更新应用程序线程中的GUI,不做那是另一个线程。我建议使用QThread和signals来执行此任务。是否发布了所有代码?我没有看到post NOW上的QObject::connectfull代码您在哪里创建了_线程变量?def testTelnet_start():Qt和PyQt的基本规则,只更新应用程序线程中的GUI,不要这样做,因为这是另一个线程。我建议使用QThread和signals来执行此任务。是否发布了所有代码?我在post NOW上没有看到QObject::connectfull代码您在哪里创建了_线程变量?def testTelnet_start():