Hacker News new | past | comments | ask | show | jobs | submit login
Avoiding random crashes when multithreading Qt (medium.com/armin.samii)
1 point by artoonie on Dec 6, 2018 | hide | past | favorite | 2 comments



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


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.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: