,Спасибо за объяснение

йной ночи я пытаюсь создать исключение в этом примере кода, исключение генерирует, если во время изменения текста в QLineEdit текст не может быть преобразован в число.

Однако, когда я бегу, я получаю сообщение об ошибке, и программа останавливается

ошибка:

QObject::setParent: Cannot set parent, new parent is in a different thread

это код:

from PyQt5.QtWidgets import QMainWindow, QApplication, QMessageBox
from PyQt5 import QtCore
from PyQt5 import uic 
import threading

class TheThread(threading.Thread):
    def __init__(self,text):
        threading.Thread.__init__(self)
        self.tx = text
    def run(self):
        try:
            print(int(self.tx),"number")
        except:
            QMessageBox.critical(None,"Error","Error ",QMessageBox.Ok)



class Principal(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)
        uic.loadUi("test.ui",self)


        self.lineEdit.textChanged.connect(lambda:self.evalNumeros(self.lineEdit.text()))

    @QtCore.pyqtSlot(str)
    def evalNumeros(self,texto):
        print(texto)
        try:
            threadClass = TheThread(texto)
            threadClass.start()
        except:
            print("error")

app = QApplication([])
p = Principal()
p.show()
app.exec_()

это filu.ui для этого кода test.ui

<?xml version="1.0" encoding="UTF-8"?>
            <ui version="4.0">
             <class>MainWindow</class>
             <widget class="QMainWindow" name="MainWindow">
              <property name="geometry">
               <rect>
                <x>0</x>
                <y>0</y>
                <width>641</width>
                <height>479</height>
               </rect>
              </property>
              <property name="windowTitle">
               <string>MainWindow</string>
              </property>
              <widget class="QWidget" name="centralwidget">
               <widget class="QLineEdit" name="lineEdit">
                <property name="geometry">
                 <rect>
                  <x>200</x>
                  <y>100</y>
                  <width>191</width>
                  <height>20</height>
                 </rect>
                </property>
               </widget>
               <widget class="QLabel" name="yes">
                <property name="geometry">
                 <rect>
                  <x>170</x>
                  <y>150</y>
                  <width>111</width>
                  <height>31</height>
                 </rect>
                </property>
                <property name="styleSheet">
                 <string notr="true">color:white;
            background:red;</string>
                </property>
                <property name="text">
                 <string/>
                </property>
               </widget>
               <widget class="QLabel" name="no">
                <property name="geometry">
                 <rect>
                  <x>300</x>
                  <y>150</y>
                  <width>111</width>
                  <height>31</height>
                 </rect>
                </property>
                <property name="styleSheet">
                 <string notr="true">color:white;
            background:green;</string>
                </property>
                <property name="text">
                 <string/>
                </property>
               </widget>
              </widget>
              <widget class="QMenuBar" name="menubar">
               <property name="geometry">
                <rect>
                 <x>0</x>
                 <y>0</y>
                 <width>641</width>
                 <height>21</height>
                </rect>
               </property>
              </widget>
              <widget class="QStatusBar" name="statusbar"/>
             </widget>
             <resources/>
             <connections/>
            </ui>

Ответы на вопрос(1)

Ваш ответ на вопрос