Now I am simple testing QPushButton. I am trying simple by clicking push button get number of spin box into QLabel. I done it. But only in the same class. In order to succeed I need to transfer it to another class. I found some examples how to do it but there goes errors:
p:3: error: redefinition of 'Tree::Tree(QWidget*)'
Tree::Tree(QWidget*)' previously defined here
and the code:
#ifndef CREATEPLANET_H
#define CREATEPLANET_H
#include <QtGui>
class CreatePlanet : public QWidget
{
Q_OBJECT
private:
QGridLayout *grdLayout;
public:
explicit CreatePlanet(QWidget *parent = 0);
QSpinBox *sizeSpinbox;
QLabel *lbl;
signals:
void spinBoxValue(int);
public slots:
void applyButtonClicked ();
};
#endif // CREATEPLANET_H
#include "createplanet.h"
CreatePlanet::CreatePlanet(QWidget *parent) :
QWidget(parent)
{
QLabel *planetNameLabel = new QLabel("Name of planet:",this);
QLineEdit *planetNameEdit = new QLineEdit();
QLabel *sizeLabel = new QLabel("Select size of the planet:");
sizeSpinbox = new QSpinBox(this);
sizeSpinbox->setRange(1,7);
QPushButton *applySizeButton = new QPushButton("Apply",this);
connect(applySizeButton,SIGNAL(clicked()),this,SLOT(applyButtonClicked()));
// lbl = new QLabel("skaicius:",this);
grdLayout = new QGridLayout(this);
grdLayout->addWidget(planetNameLabel,0,0,1,1);
grdLayout->addWidget(planetNameEdit,0,1,1,2);
grdLayout->addWidget(sizeLabel,1,0,1,1);
grdLayout->addWidget(sizeSpinbox,1,1,1,1);
grdLayout->addWidget(applySizeButton,2,0,1,1);
// grdLayout->addWidget(lbl,3,0,1,1);
this ->setLayout(grdLayout);
}
void CreatePlanet::applyButtonClicked()
{
lbl->setNum(sizeSpinbox->value());
emit spinBoxValue(sizeSpinbox->value());
}
#ifndef TREE_H
#define TREE_H
#include <QtGui>
#include "createplanet.h"
class Tree : public QWidget
{
Q_OBJECT
private:
CreatePlanet createplanet;
QLabel *lbl;
QGridLayout *grdLayout;
public:
Tree(QWidget *parent = 0)
{
connect(&createplanet,SIGNAL(spinBoxValue(int)),this,SLOT(setNumberLabel(int)));
}
signals:
public slots:
private slots:
void setNumberLabel(int inum)
{
lbl->setNum(inum);
}
};
#endif // TREE_H