How to generate an exception in a different thread





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







1















good night I am trying to generate an exception in this example code, the exception of generates if at the time of changing the text in the QLineEdit the text could not be converted into a number.



However, when I'm running, I get an error and the program stops



error:



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


this is the code:



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


enter image description here



this is the filu.ui for this code
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>









share|improve this question































    1















    good night I am trying to generate an exception in this example code, the exception of generates if at the time of changing the text in the QLineEdit the text could not be converted into a number.



    However, when I'm running, I get an error and the program stops



    error:



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


    this is the code:



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


    enter image description here



    this is the filu.ui for this code
    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>









    share|improve this question



























      1












      1








      1








      good night I am trying to generate an exception in this example code, the exception of generates if at the time of changing the text in the QLineEdit the text could not be converted into a number.



      However, when I'm running, I get an error and the program stops



      error:



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


      this is the code:



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


      enter image description here



      this is the filu.ui for this code
      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>









      share|improve this question
















      good night I am trying to generate an exception in this example code, the exception of generates if at the time of changing the text in the QLineEdit the text could not be converted into a number.



      However, when I'm running, I get an error and the program stops



      error:



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


      this is the code:



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


      enter image description here



      this is the filu.ui for this code
      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>






      python python-3.x pyqt pyqt5 qthread






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 3 at 23:15









      eyllanesc

      86.6k103564




      86.6k103564










      asked Jan 3 at 5:40









      Mystic_ForceMystic_Force

      1748




      1748
























          1 Answer
          1






          active

          oldest

          votes


















          1














          The problem is that you can not invoke the GUI directly in another thread, so there are 2 possible solutions: use a signal to invoke a method that shows the QMessageBox or use QMetaObject.invokeMethod to invoke that method, in this case I will use the second since the first one there are many examples in SO.



          from PyQt5 import QtCore, QtWidgets, uic
          from PyQt5 import uic
          import threading

          class TheThread(threading.Thread):
          def __init__(self, text, obj):
          threading.Thread.__init__(self)
          self.tx = text
          self.obj = obj

          def run(self):
          try:
          print(int(self.tx),"number")
          except:
          QtCore.QMetaObject.invokeMethod(self.obj, "onError",
          QtCore.Qt.QueuedConnection,
          QtCore.Q_ARG(str, "Error"),
          QtCore.Q_ARG(str, "Error"))


          class Principal(QtWidgets.QMainWindow):
          def __init__(self):
          super(Principal, self).__init__()
          uic.loadUi("test.ui",self)
          self.lineEdit.textChanged.connect(self.evalNumeros)

          @QtCore.pyqtSlot(str)
          def evalNumeros(self,texto):
          threadClass = TheThread(texto, self)
          threadClass.start()

          @QtCore.pyqtSlot(str, str)
          def onError(self, title, text):
          QtWidgets.QMessageBox.critical(None, title, text, QtWidgets.QMessageBox.Ok)


          app = QtWidgets.QApplication()
          p = Principal()
          p.show()
          app.exec_()





          share|improve this answer
























          • ,In this case it is not possible to just call the onError method that is in the other class from the TheThread () class instead of doing this: QtCore.QMetaObject.invokeMethod

            – Mystic_Force
            Feb 22 at 18:36













          • @Mystic_Force No, the GUI should only be updated from the main thread. If you call onError in run you would be updating the GUI from another thread and that is not correct, that is, nobody guarantees that its code works correctly

            – eyllanesc
            Feb 22 at 18:44











          • ,thanks for the explanation

            – Mystic_Force
            Feb 22 at 18:46












          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54016884%2fhow-to-generate-an-exception-in-a-different-thread%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          The problem is that you can not invoke the GUI directly in another thread, so there are 2 possible solutions: use a signal to invoke a method that shows the QMessageBox or use QMetaObject.invokeMethod to invoke that method, in this case I will use the second since the first one there are many examples in SO.



          from PyQt5 import QtCore, QtWidgets, uic
          from PyQt5 import uic
          import threading

          class TheThread(threading.Thread):
          def __init__(self, text, obj):
          threading.Thread.__init__(self)
          self.tx = text
          self.obj = obj

          def run(self):
          try:
          print(int(self.tx),"number")
          except:
          QtCore.QMetaObject.invokeMethod(self.obj, "onError",
          QtCore.Qt.QueuedConnection,
          QtCore.Q_ARG(str, "Error"),
          QtCore.Q_ARG(str, "Error"))


          class Principal(QtWidgets.QMainWindow):
          def __init__(self):
          super(Principal, self).__init__()
          uic.loadUi("test.ui",self)
          self.lineEdit.textChanged.connect(self.evalNumeros)

          @QtCore.pyqtSlot(str)
          def evalNumeros(self,texto):
          threadClass = TheThread(texto, self)
          threadClass.start()

          @QtCore.pyqtSlot(str, str)
          def onError(self, title, text):
          QtWidgets.QMessageBox.critical(None, title, text, QtWidgets.QMessageBox.Ok)


          app = QtWidgets.QApplication()
          p = Principal()
          p.show()
          app.exec_()





          share|improve this answer
























          • ,In this case it is not possible to just call the onError method that is in the other class from the TheThread () class instead of doing this: QtCore.QMetaObject.invokeMethod

            – Mystic_Force
            Feb 22 at 18:36













          • @Mystic_Force No, the GUI should only be updated from the main thread. If you call onError in run you would be updating the GUI from another thread and that is not correct, that is, nobody guarantees that its code works correctly

            – eyllanesc
            Feb 22 at 18:44











          • ,thanks for the explanation

            – Mystic_Force
            Feb 22 at 18:46
















          1














          The problem is that you can not invoke the GUI directly in another thread, so there are 2 possible solutions: use a signal to invoke a method that shows the QMessageBox or use QMetaObject.invokeMethod to invoke that method, in this case I will use the second since the first one there are many examples in SO.



          from PyQt5 import QtCore, QtWidgets, uic
          from PyQt5 import uic
          import threading

          class TheThread(threading.Thread):
          def __init__(self, text, obj):
          threading.Thread.__init__(self)
          self.tx = text
          self.obj = obj

          def run(self):
          try:
          print(int(self.tx),"number")
          except:
          QtCore.QMetaObject.invokeMethod(self.obj, "onError",
          QtCore.Qt.QueuedConnection,
          QtCore.Q_ARG(str, "Error"),
          QtCore.Q_ARG(str, "Error"))


          class Principal(QtWidgets.QMainWindow):
          def __init__(self):
          super(Principal, self).__init__()
          uic.loadUi("test.ui",self)
          self.lineEdit.textChanged.connect(self.evalNumeros)

          @QtCore.pyqtSlot(str)
          def evalNumeros(self,texto):
          threadClass = TheThread(texto, self)
          threadClass.start()

          @QtCore.pyqtSlot(str, str)
          def onError(self, title, text):
          QtWidgets.QMessageBox.critical(None, title, text, QtWidgets.QMessageBox.Ok)


          app = QtWidgets.QApplication()
          p = Principal()
          p.show()
          app.exec_()





          share|improve this answer
























          • ,In this case it is not possible to just call the onError method that is in the other class from the TheThread () class instead of doing this: QtCore.QMetaObject.invokeMethod

            – Mystic_Force
            Feb 22 at 18:36













          • @Mystic_Force No, the GUI should only be updated from the main thread. If you call onError in run you would be updating the GUI from another thread and that is not correct, that is, nobody guarantees that its code works correctly

            – eyllanesc
            Feb 22 at 18:44











          • ,thanks for the explanation

            – Mystic_Force
            Feb 22 at 18:46














          1












          1








          1







          The problem is that you can not invoke the GUI directly in another thread, so there are 2 possible solutions: use a signal to invoke a method that shows the QMessageBox or use QMetaObject.invokeMethod to invoke that method, in this case I will use the second since the first one there are many examples in SO.



          from PyQt5 import QtCore, QtWidgets, uic
          from PyQt5 import uic
          import threading

          class TheThread(threading.Thread):
          def __init__(self, text, obj):
          threading.Thread.__init__(self)
          self.tx = text
          self.obj = obj

          def run(self):
          try:
          print(int(self.tx),"number")
          except:
          QtCore.QMetaObject.invokeMethod(self.obj, "onError",
          QtCore.Qt.QueuedConnection,
          QtCore.Q_ARG(str, "Error"),
          QtCore.Q_ARG(str, "Error"))


          class Principal(QtWidgets.QMainWindow):
          def __init__(self):
          super(Principal, self).__init__()
          uic.loadUi("test.ui",self)
          self.lineEdit.textChanged.connect(self.evalNumeros)

          @QtCore.pyqtSlot(str)
          def evalNumeros(self,texto):
          threadClass = TheThread(texto, self)
          threadClass.start()

          @QtCore.pyqtSlot(str, str)
          def onError(self, title, text):
          QtWidgets.QMessageBox.critical(None, title, text, QtWidgets.QMessageBox.Ok)


          app = QtWidgets.QApplication()
          p = Principal()
          p.show()
          app.exec_()





          share|improve this answer













          The problem is that you can not invoke the GUI directly in another thread, so there are 2 possible solutions: use a signal to invoke a method that shows the QMessageBox or use QMetaObject.invokeMethod to invoke that method, in this case I will use the second since the first one there are many examples in SO.



          from PyQt5 import QtCore, QtWidgets, uic
          from PyQt5 import uic
          import threading

          class TheThread(threading.Thread):
          def __init__(self, text, obj):
          threading.Thread.__init__(self)
          self.tx = text
          self.obj = obj

          def run(self):
          try:
          print(int(self.tx),"number")
          except:
          QtCore.QMetaObject.invokeMethod(self.obj, "onError",
          QtCore.Qt.QueuedConnection,
          QtCore.Q_ARG(str, "Error"),
          QtCore.Q_ARG(str, "Error"))


          class Principal(QtWidgets.QMainWindow):
          def __init__(self):
          super(Principal, self).__init__()
          uic.loadUi("test.ui",self)
          self.lineEdit.textChanged.connect(self.evalNumeros)

          @QtCore.pyqtSlot(str)
          def evalNumeros(self,texto):
          threadClass = TheThread(texto, self)
          threadClass.start()

          @QtCore.pyqtSlot(str, str)
          def onError(self, title, text):
          QtWidgets.QMessageBox.critical(None, title, text, QtWidgets.QMessageBox.Ok)


          app = QtWidgets.QApplication()
          p = Principal()
          p.show()
          app.exec_()






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jan 3 at 15:49









          eyllanesceyllanesc

          86.6k103564




          86.6k103564













          • ,In this case it is not possible to just call the onError method that is in the other class from the TheThread () class instead of doing this: QtCore.QMetaObject.invokeMethod

            – Mystic_Force
            Feb 22 at 18:36













          • @Mystic_Force No, the GUI should only be updated from the main thread. If you call onError in run you would be updating the GUI from another thread and that is not correct, that is, nobody guarantees that its code works correctly

            – eyllanesc
            Feb 22 at 18:44











          • ,thanks for the explanation

            – Mystic_Force
            Feb 22 at 18:46



















          • ,In this case it is not possible to just call the onError method that is in the other class from the TheThread () class instead of doing this: QtCore.QMetaObject.invokeMethod

            – Mystic_Force
            Feb 22 at 18:36













          • @Mystic_Force No, the GUI should only be updated from the main thread. If you call onError in run you would be updating the GUI from another thread and that is not correct, that is, nobody guarantees that its code works correctly

            – eyllanesc
            Feb 22 at 18:44











          • ,thanks for the explanation

            – Mystic_Force
            Feb 22 at 18:46

















          ,In this case it is not possible to just call the onError method that is in the other class from the TheThread () class instead of doing this: QtCore.QMetaObject.invokeMethod

          – Mystic_Force
          Feb 22 at 18:36







          ,In this case it is not possible to just call the onError method that is in the other class from the TheThread () class instead of doing this: QtCore.QMetaObject.invokeMethod

          – Mystic_Force
          Feb 22 at 18:36















          @Mystic_Force No, the GUI should only be updated from the main thread. If you call onError in run you would be updating the GUI from another thread and that is not correct, that is, nobody guarantees that its code works correctly

          – eyllanesc
          Feb 22 at 18:44





          @Mystic_Force No, the GUI should only be updated from the main thread. If you call onError in run you would be updating the GUI from another thread and that is not correct, that is, nobody guarantees that its code works correctly

          – eyllanesc
          Feb 22 at 18:44













          ,thanks for the explanation

          – Mystic_Force
          Feb 22 at 18:46





          ,thanks for the explanation

          – Mystic_Force
          Feb 22 at 18:46




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54016884%2fhow-to-generate-an-exception-in-a-different-thread%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          MongoDB - Not Authorized To Execute Command

          How to fix TextFormField cause rebuild widget in Flutter

          Npm cannot find a required file even through it is in the searched directory