lundi 26 octobre 2015

Signal/Slot between classes and Design of Classes

suppose I've the following classes :

class A:public QObject{
    Q_OBJECT
...
signals:
   void sendData(QString data);
}

class B:public QObject{
    Q_OBJECT

  public:
     A a;
...
public slots:
  void onSendData(QString);
signals:
   void  sendData(QString data);
}


class C:public QObject{
    Q_OBJECT

  public:
     B b;
...
public slots:
  void onSendData(QString);
signals:
   void sendData(QString data);
}

.
.
.


class MainWindow:public QMainWindow{
    Q_OBJECT

  public:
     LastClass lc;
public slots:
  void onSendData(QString);//show data on ui
}

class A digs data and when it finds a special data it must send it to ui(mainwindow) , so it calls sendData signal, then class B which contains an instance of A, grabs the signal and from it's slot sends it to above class ,...

as you can see, it causes a recursive signal/slot send and receiving which I doubt that it is a good design.

Is it a correct way or must I change the design ? ( it's hard to change design in some circumstances though). (I cannot use inheritance because each class has a different functionality and different functions.)

Aucun commentaire:

Enregistrer un commentaire