I created a signal, which is emitted when the user input something(a number) in a qlineedit field, the signal is emitted with a parametre(the number that the user just type in the field). And i would like to use that parametre as a regular number(in a variable). Im trying to add that signal parametre to another number, and i had an error "s1 is not declared". Here is my class in the .h file and his implementation in the .cpp file
the.h file
class fenetre: public QWidget
{
Q_OBJECT
public:
fenetre();
public slots:
void calc();
void clearinput();
signals:
void thesecond(int s1);
private:
QPushButton *button1;
QPushButton *button2;
QPushButton *button3;
QPushButton *button4;
QPushButton *button5;
QPushButton *result0;
QPushButton *clear;
QLineEdit *input1;
//QLineEdit *inputsqrt;
//QLineEdit *input2;
//QLineEdit *result;
//QLineEdit *square;
};
the.cpp file
QObject::connect(button1,SIGNAL(clicked()),this,SLOT(calc()));
//QObject::connect(button2,SIGNAL(clicked()),this,SLOT(calc()));
//QObject::connect(button3,SIGNAL(clicked()),this,SLOT(calc()));
//QObject::connect(button4,SIGNAL(clicked()),this,SLOT(calc()));
//QObject::connect(button5,SIGNAL(clicked()),this,SLOT(calc()));
//QObject::connect(clear,SIGNAL(clicked()),this,SLOT(clearinput()));
//QObject::connect(result0,SIGNAL(clicked()),this,SLOT(calc()));
QObject::connect(result0,SIGNAL(thesecond(int)),this,SLOT(calc()));
}
void fenetre::calc()
{
QString s=input1->text();
bool ok;
if(!input1->text().isEmpty())
{
int s1=s.toInt(&ok,10);
emit thesecond(s1);
input1->clear();
}
QObject* obj=sender();
if(obj==result0)
{
int s2=s.toInt(&ok,10);
int A=s2+thesecond(s1);
input1->clear();
QString c=QString::number(A);
input1->setText(c);
}
}