I am now trying to create a simple GUI openGL drawing program.
I use a Line2dFactory (subclass of Shape2dFactory, which is a subclass of QWidget) class to receive the values assigned by various input widgets and then wrap them up as a Line2d (subclass of Shape2d) object and send the object to openGL widget for drawing.
The Line2dFactory class looks like:
class Line2dFactory : public Shape2dFacotry
{
Q_OBJECT
public:
explicit Line2dFactory(QWidget *parent = 0);
~Line2dFactory();
signals:
// this is a member of Shape2dFacotory. for the purpose of
// illustration I put it here
void shape2dSent(Shape2d shape);
public slots:
// set begin and end points
void setX1(int i);
void setY1(int i);
void setX2(int i);
void setY2(int i);
// implement object creation, and emit the created object to display
void sendLine2d();
private:
int x1, y1, x2, y2;
Line2d line2d;
};
I connected set**(int) slots to 4 QSpinBoxes' ValueChanged(int) signals. A push button's clicked() signal is connected to sendLine2d() slot.
After the program fires up, if I change ALL the values in the QSpinBoxes via GUI and click the push button then an object is created and sent to display.
However, if I change not all the values in the spin boxes (the default is 0), the signals of those unchanged spin boxes seems to be not sent. Therefore the initial values of the corresponding points are random int
. If the push button is clicked then the program will freeze the computer since it try to compute likely a very long line.
My question is: What signal could I connect the set** slot to to make the factory class know about the initial value of the Qspinbox? And, more generally, for other gui components?
I don't want to assign a value manually since I might forget to change both if I decide to change the default value.