1

Dears, I am new on python and trying to start python networking with a simple code that have 2 plain text line edits and try to start 2 telnet sessions and get output of each session on a separate plain text line area however i get the below error

QObject::connect: Cannot queue arguments of type 'QTextCursor' (Make sure 'QTextCursor' is registered using qRegisterMetaType().)

the code as below:

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_()

Any idea why a simple multi threading code cause those errors ?

Thanks.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241

0 Answers0