我对模型视图控制器有疑问。我把函数connect放在类Controller中,但是我不知道它是对还是错。也许认为更好。我能怎么做?用户应向控制器而不是视图提出请求。
class Model{
public:
string name;
}
class View:public QMainWindow{
public:
Model* m;
View(QWidget* parent, Model* m):QMainWindow(parent), m(m){
QLabel *label = new QLabel(this);
QPushButton* button=new QPushButton("Button", this);
button->setGeometry(QRect(QPoint(100, 100),QSize(200, 50)));
}
class Controller{
private:
Model* m; View* v;
public:
Controller(Model* m, View* v):m(m),v(v){
QObject::connect(v.button, SIGNAL (clicked()), v.label, SLOT(Click());
}
void Click(){
v.label->setText(m.name);
}
}
int main(int argc, char *argv[]){
Model m;
Qwidget* parent=new QWidget();
View v(parent, &m);
Controller(&m,&v);
v.show();
}