On the eve of doing a simple application, namely the graph on the curves Lissajous. Almost did everything, but there is a small snag.

class LissageFunction : public QObject { Q_OBJECT public: LissageFunction(QObject *obj = 0); void setFunction(double wa, double wy, double w1, double w2); double getWx(); double getWy(); double getW1(); double getW2(); void setFunctionInPoints(); QVector<QPointF> getFunctionInPoints(); private: double Wx; double Wy; double W1; double W2; QVector<QPointF> function; public slots: void setValueWx(double wx){ this->Wx = wx; emit changeFunction()};//пример void setValueWy(double); void setValueW1(double); void setValueW2(double); signals: void changeFunction(); }; 

In general, there is a class on lissage curves, a separate widget that represents a coordinate grid and 4 separate QSpinBox-ksa for the parameters Wx, Wy, W1, W2 - which are supposed to regulate these equations:

x (t) = sin (Wx * t + W1); y (t) = sin (Wy * t + W2);

I, let's say regulate the values ​​and send a signal

 QSpinBox *Wx = new QSpinBox; connect(Wx,SIGNAL(valueChanged(int)),LissageFunction,SLOT(setValueWx(double))); 

(further in theory, I will simply send a signal to change the value, and the slot from the graphics widget will redraw from the override function paintEvent;)

I do not fully understand the mechanism of signals and slots, but from the Schlee textbook, too primitive or ready-made examples of their interaction between widgets.

Do I understand correctly that you need to separately inherit Spinboxes and define your signals for my class, or does the valueChanged (int) signal somehow implicitly pass the value to the slot? If so, how to process it in the setValueWx signal (double) to change the value of the variable

  • Signal valueChanged(int) quite clearly conveys the value in the parameter - Bearded Beaver
  • Yes, that's right, they are transmitted explicitly) - Gleb

1 answer 1

I found one solution in order to understand from which signal of the spinbox the value came and to remove its value, you can by this line

 int x = ((QSpinBox*)sender())->value(); 

In the described slot.

PS values ​​in the signals are transmitted to the slot explicitly, so it can be processed directly from the slot parameter without the above written function. And also, so that the signal and slot would have the same type, without int -> double, as it was with me.