Settings

Theme

Avoiding random crashes when multithreading Qt

medium.com

1 points by artoonie 7 years ago · 2 comments

Reader

billconan 7 years ago

the first example code is an expected issue, according to Qt's document, only the main thread should update the gui:

GUI Thread and Worker Thread As mentioned, each program has one thread when it is started. This thread is called the "main thread" (also known as the "GUI thread" in Qt applications). The Qt GUI must run in this thread. All widgets and several related classes, for example QPixmap, don't work in secondary threads. A secondary thread is commonly referred to as a "worker thread" because it is used to offload processing work from the main thread.

http://doc.qt.io/qt-5/thread-basics.html

  • artoonieOP 7 years ago

    Point is (and I should clarify in the post): qt doesn't document which functions do and don't update the GUI, and you have no guarantees when calling an arbitrary Qt function that it won't. This is practical advice to stay safe. A seemingly innocuous Qt function might internally update the GUI, as shown in the example.

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection