I have been working on a project in Qt.
There is parent class which adds all the GUI content when my program runs on startup.
However after taking user input I am performing some mathematical operations in various other classes to check for incorrect user input (each class for a particular type of error). The objects of these classes have been moved to other threads (obj->movetothread(thread)) which I have created. Thus I can simultaneously check all the errors by multi-threading. The problem is that whenever there is incorrect user input I want to throw a MessageBox containing information about that corresponding error. Since the error checking is done on non-GUI thread it is currently crashing my program. So my only option is to keep a reference of the QString containing that error & when finally I return from all error checks, I throw Messageboxe’s one after other in the GUI thread. This process is very cumbersome I would like to know if there is any workaround available to solve this problem?
PS: Long story short, how to add GUI content in non-GUI thread, in multi threaded applications?
You do not have to manipulate the GUI from a non-GUI thread. A good way to go is to emit a signal from your worker thread when you need to manipulate the GUI and wait for the answer of the user (like on a QSemaphore or whatever you prefer). Connect that signal to a slot implemented in a QObject living in the GUI thread using a Qt::QueuedConnection. This will run the slot in the GUI thread.
You can find whatever you need on this subject around anyway. Just start searching.