Best way for multi-threaded interface?

As stated in the documentation, the Qt GUI should be accessible only from the main thread. For a complex application with several large and busy tables, this can be the bottleneck of all the font-size calculations that Qt likes to do. The only alternative I can come up with is multitasking with separate processes. Tables are currently as fast as you can get, a custom model that maps directly to a cache that is served from another thread using dataChanged () calls in the most conservative set of modified cells. I already profiled vTune, 70% of the application time is now in Qt's rendering code. Any suggestions?

+4
source share
3 answers

I have not used QT, but accessing the GUI from only one thread (GUI thread) is a well-known issue in almost any GUI that I am familiar with. I used 2 solutions for this case, of which I prefer the first:

1) Your form will update the GUI (table in this case) at timer intervals. A timer is activated in GUI thread events. On these timer events, you read data from global vars and update the table. Global vars can be updated as many streams as possible. You may need to synchronize (e.g. semaphores) access to global vars.

2) In many GUIs, threads can update the GUI by passing the GUI thread to a function (or object) and request it to execute it as soon as possible in its context. The calling thread, meanwhile, blocks until the GUI performs an action. I can recall three such functions - Invoke , InvokeLater from Java and C # or wx.CallAfter from wxPython.

+5
source

Use the MVC pattern option and make the model multithreaded

+3
source

If your table entries and methods are completed in several steps, you can call QCoreApplication :: processEvents () to update qt ui between calculations. Another thing you can do is run everything on different threads and emit signals from the stream when the calculations are complete. In the end, updates are performed on ui from the main thread, but asynchronously. To connect to a signal from another stream, you will need to use qRegisterMetaType <> .

+2
source

All Articles