I am afraid I don't understand what you are looking for.
Your initial approach looked fine!
Cheers,
_
I am afraid I don't understand what you are looking for.
Your initial approach looked fine!
Cheers,
_
My initial example's model is looking like controller.Probably i shoold make separate model class for every table from the sql.I can't belive that there is no example in the net.
My view and controller are not like they should be, but i don't know how to connect them in the shown example.
There are plenty of QSql examples, quite some of them using models http://doc.qt.io/qt-5/sql-examples.html
if you don't want to use the models from the QSql module, have a look at the model/view documentation:
http://doc.qt.io/qt-5/modelview.html
http://doc.qt.io/qt-5/model-view-programming.html
Cheers,
_
Dear @anda_skoa
Before ask here i observe all possible in Qt documentation and in internet.
I have reviewed these examples, but as i see they are not pure MVC, or i'm wrong?!
What about this example http://doc.qt.io/qt-5/qtsql-querymodel-example.html
Is this pure MVC?It seems that in this case the main.cpp plays the role of controller?Is this the right approach, the controller to be the main class?
This is similar to my first approach.
Well, that's up to you.
The example isn't that complex so its author likely decided against an explicit controller class.
Doesn't mean you can't do that, i.e. like you had in your first posting in this thread.
But if you like you can also make the controller part of the model class, or spread it across, model, view and delegate.
Cheers,
_
i really need an example of real MVC construction.I also read that the view should emit only signals.... and the controller take the other part.Nothing more the view shuld have.I'm very confuse , really!
I really don't understand what you are looking for.
You have view and model. So any class that reacts to the signals of the view and manipulates the model, or the data the model is working on, is the controller.
Which is what you had in your first posting, no?
Cheers,
_
inmy first code i mixed the model with the controller
Well, the controller created the model instance, but you could as easily pass the externally constructed model to it.
Cheers,
_
cpuinthebrain (28th July 2015)
I still need an example, sorry , but the mess is still in my head
Lets assume for simplicity that the controller creates and owns the model (but you can make it setable with a bit of more effort)
Qt Code:
{ Q_OBJECT public: public slots: void updateModel(); private: QSqlQueryModel *m_model; private slots: };To copy to clipboard, switch view to plain text modeQt Code:
{ } { // could also install a custom delegate here and connect to it } void Controller::updateModel() { m_model->setQuery(...); } { // do whatever needs to be done }To copy to clipboard, switch view to plain text mode
This is what i can't understand.
Why the controller should contain the model?You mean because in our case the model is the DataBase?If it was ORM or QObject it would be in different class, right?
By the way many thanks for your time and for the example!
Bookmarks