1

I am adding a PyQT UI to an existing application. I have to initialize the QAppliaction via a callback that I receive from that application on the main thread. I can't do that synchronously from the callback because I would eventually have to call app.exec() which is blocking, preventing the existing application from continuing. Obviously, spawning a regular thread does not work, and I cannot seem to find a way to do it with a QThread.

This question seems to do exactly what I want in C:

thread = new QThread();
connect(thread, SIGNAL(started()), this, SLOT(onStarted()), Qt::DirectConnection);
thread->start();

where onStarted eventually calls exec(). Apparently I am not intelligent enough to achieve the exact same thing in Python. How does it work?

Simon Fischer
  • 1,154
  • 6
  • 22
  • 2
    Qt does not support GUI operations of any kind outside the main thread. So there's no way to safely create a `QApplication` (as opposed to a `QCoreApplication`) and/or a UI in another thread, You should create the `QAppplication` *first*, then use a [single-shot timer](https://doc.qt.io/qt-5/qtimer.html#singleShot) to queue up the other application, before calling `exec()`. Once the Qt event-loop starts, the timer will immediately time-out and the other application will start. – ekhumoro Sep 30 '22 at 22:12

0 Answers0