PyQt5 cannot update progress bar from thread and received the error "Cannot create children for a parent that is in a different thread"

Asked
Active3 hr before
Viewed126 times

6 Answers

progresscannotchildrenparentcreatedifferent
90%

It appears as though the image does get uploaded to the remote main server when using "Import appliance", I am experimenting with NETem (image is 25Mb)

Example_snippet/controller/utility/_progress.js/ Fix #1915. . .
Fix #1915
load more v
88%

An Introduction to QThreads,You may not post new threads,Welcome to Qt Centre,,You may not post replies

Example_snippet/controller/utility/_progress.js/ MyThread::MyThread():QThread(). . .
MyThread::MyThread(): QThread() {
      process = new QProcess(this); // QProcess process; in the class}
Step 2 continued with MyThread::MyThread():QThread(). . .
MyThread::MyThread(): QThread() {
      process = new QProcess(this); // QProcess process; in the class}
Step 3 continued with MyThread::MyThread():QThread(). . .
MyThread::MyThread(): QThread() {
   process = new QProcess(this); // QProcess process; in the class
}
load more v
72%

I have created now a worker,py that contains:,I hope this helps people

Example_snippet/controller/utility/_progress.js/ from PyQt5 import QtCore, QtGu. . .
from PyQt5
import QtCore, QtGui, QtWidgets
import threading

class menubar(object):
   def __init__(self):
   signal.signal(signal.SIGINT, signal.SIG_DFL)
self.systray = True
self.stopped = False

def search_menu(self):
   self.SearchAction = menu.addAction("Search")
self.SearchAction.triggered.connect(self.search_cast)

def _search_cast_(self):
   args.select_cc = True
self.cc.initialize_cast()
self.cast_list()

def search_cast(self):
   threading.Thread(target = self._search_cast_).start()

#some more methods here...

   def main():

   menubar()
app = QtWidgets.QApplication(sys.argv)
tray = QtWidgets.QSystemTrayIcon(icon)

menu = QtWidgets.QMenu()
start = menubar()
start.search_menu()
start.separator_menu()
start.populating_menu()
start.separator_menu()
start.stop_menu()
start.resetaudio_menu()
start.about_menu()
start.exit_menu()

tray.setContextMenu(menu)
tray.show()
app.exec_()

if __name__ == '__main__':
   main()
Step 2 continued with QObject: Cannot create childre. . .
QObject: Cannot create children
for a parent that is in a different thread.
   (Parent is QMenu(0x7fcef497c160), parent 's thread is     QThread(0x7fcef2603d10), current thread is QThread(0x7fcef4a89360)
      QObject: Cannot create children
      for a parent that is in a different thread.
      (Parent is QMenu(0x7fcef497c160), parent 's thread is  QThread(0x7fcef2603d10), current thread is QThread(0x7fcef4a89360)
         QObject: Cannot create children
         for a parent that is in a different thread.
Step 3 continued with from PyQt5.QtCore import QThre. . .
from PyQt5.QtCore
import QThread, QObject, pyqtSignal, pyqtSlot
#some other imports

class Worker(QObject):
   finished = pyqtSignal()

@pyqtSlot()
def _search_cast_(self):
   self.cc = casting()
self.cc.initialize_cast()
self.finished.emit()
Step 4 continued with class menubar(object): def. . .
class menubar(object):
   def __init__(self):
   self.cc = casting()
signal.signal(signal.SIGINT, signal.SIG_DFL)
self.cc.cast = None
self.systray = True
self.stopped = False

self.obj = worker.Worker() # no parent!
   self.thread = QThread() # no parent!
   self.obj.moveToThread(self.thread)
self.obj.finished.connect(self.thread.quit)
self.thread.started.connect(self.obj._search_cast_)

def search_menu(self):
   self.SearchAction = menu.addAction("Search")
self.SearchAction.triggered.connect(self.search_cast)

def search_cast(self):
   self.thread.start()
self.cast_list()

def cast_list(self):
   if len(self.cc.availablecc) == 0:
   # some actions here.
Step 5 continued with AttributeError: 'casting' obj. . .
 AttributeError: 'casting'
 object has no attribute 'availablecc'
load more v
65%

i wrote a small GUI to train different machine learning models, To keep the GUI responsive i am using QThread

Example_snippet/controller/utility/_cannot.js/ QObject: Cannot create childre. . .
QObject: Cannot create children
for a parent that is in a different thread.
   (Parent is QTextDocument(0x2316d8786c0), parent 's thread is QThread(0x2315f43caa0), current thread is WorkerThread(0x23172a30e30)
      forrtl: error(200): program aborting due to control - C event Image PC Routine Line Source libifcoremd.dll 00007 FFD14DC3B58 Unknown Unknown Unknown KERNELBASE.dll 00007 FFD6255B443 Unknown Unknown Unknown KERNEL32.DLL 00007 FFD62AE7034 Unknown Unknown Unknown ntdll.dll 00007 FFD64A5D0D1 Unknown Unknown Unknown QObject::~QObject: Timers cannot be stopped from another thread
75%

Example_snippet/controller/utility/_cannot.js/ You have two choices: - imple. . .
You have two choices:

   -implement every method required by the interface
or
   -
   declare the missing methods abstract in your class.This forces you
to declare your class abstract and, as a result, forces you to
subclass the class(and implement the missing methods) before you
can create any objects.
40%

Your code has several errors since PyQt has certain minimum rules:,The thread where the GUI application is created is called GUI thread because there must be created and live any graphic component, but you are creating unnecessary RPTApp inside the QThread, I say unnecessary since the thread is created inside RPTApp so it does not it is necessary to create another,, Another question

Example_snippet/controller/utility/_cannot.js/ class ExecuteSession(QThread):. . .
class ExecuteSession(QThread):
   PBValueSig = pyqtSignal(int)[...]
def run(self):
   i = 0
while i <= self.dur:
   print(i)
i = i + 1
self.PBValueSig.emit(i)
time.sleep(1)

class RPTApp(QMainWindow, Ui_MainWindow): [..]
def PB(self):
   dur = 10
self.progressBar.setMinimum(0)
self.progressBar.setMaximum(dur)
self.progressBar.setValue(0)
# thread
self.exeThread = ExecuteSession(dur)
self.exeThread.PBValueSig.connect(self.updateProgressBar)
self.exeThread.start()

@pyqtSlot(int)
def updateProgressBar(self, value):
   print("INT + " + str(value))
self.progressBar.setValue(value)