vendredi 6 avril 2018

get property from mainWidget

I have tree widgets structure, main widget has pointers to children widgets and chilrdren widget has pointers to their chirldrens and so on... How leaves (chirldrens) can get data from mainWidget and connect all widgets(for examples, mainWidget has changed input file). I used signal to connect them,but it looks like spaghetti code.Is there a better way? Maybee mediator pattern? Thanks.

 //MainWidget 
 class mainWidget: public QMainWindow {
    .......
    private:
    Level1AWidget *l1aw;
    Level1BWidget *l1bw;
    .......
 }

mainWidget creates l1aw and l1bw objects in constructor

  mainWidget::mainWidget(parent):QMainWindow(parent){
  .....
  Level1AWidget *l1aw = new Level1AWidget(this);
  Level1BWidget *l1bw = new level1AWidget(this);
  ......
  }

Children widgets

 class Level1AWidget: public QWidget {
    .......
    private:
    Level1AWidget *l2aw;
    Level1BWidget *l2bw;
    .......
 }

l1aw object creates l2aw objects in constructor

  mainWidget::mainWidget(parent):QMainWindow(parent){
  .....
  Level1AWidget *l2aw = new Level1AWidget(this);
  ......
  }

How should i connect l2aw object to main object?

Aucun commentaire:

Enregistrer un commentaire