Details
Description
QInputDialog blocks the execution of child threads (implemented by Qt using QRunnable + QThreadPool, QThread, QThread + QObject or using python's threading module).
In the following demo the threads are started but as soon as the QInputDialog is shown, the execution of the threads is blocked, when the QInputDialog is closed the threads resume their execution.
import sys import threading import time from PySide6 import QtCore, QtWidgets class Runnable(QtCore.QRunnable): def run(self): fun() class Thread(QtCore.QThread): def run(self): fun() class Worker(QtCore.QObject): @QtCore.Slot() def task(self): fun() def fun(): for i in range(10): print(i) time.sleep(1) def handle_timeout(): value, ok = QtWidgets.QInputDialog.getInt( None, "QInputDialog::getInt()", "Percentage:", 25, 0, 100, 1 ) def main(): app = QtWidgets.QApplication(sys.argv) w = QtWidgets.QWidget() w.resize(640, 480) w.show() runnable = Runnable() QtCore.QThreadPool.globalInstance().start(runnable) threading.Thread(target=fun, daemon=True).start() test_thread = Thread(app) test_thread.start() worker = Worker() worker_thread = QtCore.QThread(app) worker.moveToThread(worker_thread) worker_thread.started.connect(worker.task) worker_thread.start() QtCore.QTimer.singleShot(3 * 1000, handle_timeout) ret = app.exec() test_thread.quit() test_thread.wait() worker_thread.quit() worker_thread.quit() sys.exit(-1) if __name__ == "__main__": main()
The problem happens in PySide2 and PySide6, it does not happen in PyQt5 or PyQt6.