PDA

View Full Version : design question about MVC with multithreading



justDance
28th October 2012, 23:14
This Qt application I am working on has model view controller in main thread, while the data structure under dataModel and the data model are modified by a network working thread (basically it is getting data from server). The application crashes ramdonly. Based on my triage, it shows it crashes at some Qt deep model functions triggered by my data model modification. So I put lock on those data model functions. But now it still crashes.

What is right design for this case? I also tried to promote data model modification to main thread, which means once data structure is changed, it emits a signal to controller, then the slot function in controller modifies the data model. This crashes too. plus this design looks weird. data structure changes model directly seems a better design, but it will keep model in working thread. I looked at a lot of model/view examples, all of them model contains data and model is not in worker thread. So none of them is my case.

Thanks,

ChrisW67
29th October 2012, 03:56
We cannot help you with crashes. We cannot see what you are doing. Suffice to say it is likely to be null or invalid pointers or, if you are accessing data cross-thread, then locking or thread ownership issues. Run back through the backtrace and find what in your code precipitates the crash.

Why did you feel the need to use a threaded approach at all? Qt networking doesn't require it.

justDance
29th October 2012, 06:39
Sorry, I didn't make my question clear enough. my question is more about design, not my crash.
The reason to use another thread for network communication is that the thread is also doing some other task.

My question about design is should changed underneath data container inform controller and let controller change data model? or should changed data container inform data model directly? personally i prefer the latter. but the problem of the latter one is that the size of data model is controlled by the config setting in the gui, so data container has to get the info from controller if it controls data model, which against data containers' real functionality..

Thanks,