Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 10

Qt-interest Archive, June 2003
Model View Control Patern with QT


Message 1 in thread

Hi,

I try to implement the MVC Pattern with QT. Can anyone give me a short
example how i can do this.
At the moment i have implemented a model the view and the control is one
class which i have derived from the widget class.

Thanks
Martin


Message 2 in thread

Hola~

Qt is really component based, so trying to setup a MVC paradigm within Qt is a
bit horsey.

In the past, I will create a controller that is a QWidget. In designer, I
instance the controller and use it to connect signals and slots from UI
elements. For the most part, I ended up creating derivatives of common
QWidgets that accept updates via slots. That way, after you get the initial
setup, you can sit in designer and work in much the same way you would within
Project Builder (except that you need to recompile the controller plugin for
every slot/signal change).

The result of designer is a QMainWindow derivative. I derive off this class
and hide the controller in the contructor, so the controller doesn't visually
appear in the final UI.

The model for the apps I've been dealing with is a full subsystem managed by
the controller. There's no reason to put a formal interface between the
controller and the model. The controller is thought of as per application, so
having it manage the model state is easy.

MO

>-- On Wed, Jun 25, 2003 at 03:47:06PM +0200, % wrote:
> Hi,
> 
> I try to implement the MVC Pattern with QT. Can anyone give me a short
> example how i can do this.
> At the moment i have implemented a model the view and the control is one
> class which i have derived from the widget class.
> 
> Thanks
> Martin
> 
> --
> List archive and information: http://lists.trolltech.com/qt-interest/

-- 
 [ signature omitted ] 

Message 3 in thread

On Wed, 25 Jun 2003 15:47:06 +0200, Martin Metzger wrote:
> I try to implement the MVC Pattern with QT. Can anyone give me a short
> example how i can do this.

It is quite simple.

I can send you a Subject- and a Observer-class for that if you want.

> At the moment i have implemented a model the view and the control is one
> class which i have derived from the widget class.

Then you did not understand the MVC!?


The Model is a non-qt(minimal with no qt-interface!) class that derived
from subject.

The View is a QtWidget derived from Observer. Sometimes the controller is
the same "Widget" as the view.

I can explain you more details by mail (in german) if you describe me your
problem.


Message 4 in thread

Hi,

I will try to describe my problems with the MVC in QT in Detail:

My current system:
- abstract class Observer (like in Observerpattern)
- abstract class Subject (linke in Observerpattern)

- model class e.g user derived from subject class, defines accessor methodes
to the attributes

-  QWidget e.g Userdialog, defines slot wich saves the username when a
button is pressed, this is an empty methode in this class

- Combined view and controller class which ist derived from Observer and
Userdialog, overwrites the slot methode from the class above

How can i now separate the view and the controller. Which parts are
controllerparts and which parts are viewparts. I think i haven't really
understand the pattern in this point.
- How are the associations between modell - controller -view?
- Does have anybody an uml - Diagram of this pattern? or a good page?

Makes it sense in QT to sparate the view and the controller in QT?

Thanks a lot for your help,

Martin



"Christian Buhtz" <uspam@gmx.net> wrote in message
bdccbj$7fc$1@motorkatt.troll.no">news:bdccbj$7fc$1@motorkatt.troll.no...
> On Wed, 25 Jun 2003 15:47:06 +0200, Martin Metzger wrote:
> > I try to implement the MVC Pattern with QT. Can anyone give me a short
> > example how i can do this.
>
> It is quite simple.
>
> I can send you a Subject- and a Observer-class for that if you want.
>
> > At the moment i have implemented a model the view and the control is one
> > class which i have derived from the widget class.
>
> Then you did not understand the MVC!?
>
>
> The Model is a non-qt(minimal with no qt-interface!) class that derived
> from subject.
>
> The View is a QtWidget derived from Observer. Sometimes the controller is
> the same "Widget" as the view.
>
> I can explain you more details by mail (in german) if you describe me your
> problem.


Message 5 in thread

The model is code that is completely independent of Qt.  
The view is the Qt libraries.
The controller is a widget derived from some QObject.

This is true Model-View-Controller separation.

The model code could be a processing class that takes input of some file type
and outputs a new file type.  The model code knows nothing about Qt.  If you
need to return string values from a model class, do not use QString, use
std::string/GNUString/const char*.  

The view is the Qt libs.  Obviously, the qt libraries know nothing about your
model code.

The controller is GUI code that lives between the view (the Qt libs) and your
model code.  The controller knows about both the view and the model.  The
controller is some class that is derived from QObject/QWidget.  The controller
handles all GUI interaction between the user.  If your dialog has a input text
box, then process that input as necessary, and pass the values to your model
code to do the work.

To help keep the MVC seperation, keep your model code and your controller code
in different file trees.  We use /Util for model code and /Hmi for controller
code.  

The beauty of the MVC paradigm is that you can "switch out" interface code and
not have to change your model code. 

Chad  



-----Original Message-----
From: Christian Buhtz [mailto:uspam@gmx.net]
Sent: Wednesday, June 25, 2003 10:42 AM
To: qt-interest@trolltech.com
Subject: Re: Model View Control Patern with QT


On Wed, 25 Jun 2003 15:47:06 +0200, Martin Metzger wrote:
> I try to implement the MVC Pattern with QT. Can anyone give me a short
> example how i can do this.

It is quite simple.

I can send you a Subject- and a Observer-class for that if you want.

> At the moment i have implemented a model the view and the control is one
> class which i have derived from the widget class.

Then you did not understand the MVC!?


The Model is a non-qt(minimal with no qt-interface!) class that derived
from subject.

The View is a QtWidget derived from Observer. Sometimes the controller is
the same "Widget" as the view.

I can explain you more details by mail (in german) if you describe me your
problem.

--
 [ signature omitted ]