0

I have a Main thread which owns a widget with a label I want to update repeatedly. I can loop a thousand times (a test run) when in the parent thread and it works fine. When I pass the instance of the widget into a new thread and try to do it there it will update for a bit and then stall. If I mouse over it, it updates fine and stalls again when I move the mouse away. I am assuming the mouse is forcing the widget into focus and/or an "active window" state but when I try calling either of the methods to set focus or active window state it makes no difference. Perhaps it's raising the priority of the thread?

Is there a way I can make sure each call to update the widget label is seen without moving the mouse over it?

dbc
  • 104,963
  • 20
  • 228
  • 340
  • 2
    Please provide a [mcve]. You can't modify a `QWidget` directly from any thread other than that on which `main` is running -- it's not supported. You should probably use the queued signal/slot mechanism instead. – G.M. Dec 07 '21 at 17:07
  • Does this answer your question? [Modify Qt GUI from background worker thread](https://stackoverflow.com/questions/14545961/modify-qt-gui-from-background-worker-thread) – dbc Dec 14 '21 at 00:40

1 Answers1

0

I found the answer. Connect a signal and slot such that the signal is emitted in the thread calling the slot on the main thread which will update the widget with a new value set in the thread.