问题描述:

Is it a good idea to have the Model part of a MVC application live in a different thread than the View part (GUI) of the application?

Let me elaborate a bit.

We are working on a Qt GUI Application. We have a few Model classes which are used to model computations, i.e. the Model objects will form a graph in which the nodes represent computations and the edges data flow. The GUI is used to assemble this graph. The Model classes are all derived from QObject and use the Signal/Slot mechanism to pass data between them and to signal state change to the View.

One important requirement is, that it must be possible to execute the computation in a separate thread. The architect on our team therefore decided to have all the model objects live in a separate thread all the time. This obviously means, that signals between model and GUI always go over the event queue and that communication is therefore mostly asynchronous. The argument for this design is simply that it seems very difficult to do it in any other way at this point in the project.

What is your opinion? Do you think that this is a good design? Have you used such a design yourself? What can go wrong? How would you approach the parallel execution requirement?

相关阅读:
Top