No such slot ?
-
Hey guys , sorry for asking lots of questions first :(
second , I just finished my midterms " finally " :D , and I wanted to make a little calculator " I'm new so please don't get mad at me :D "
so first I used a class that I used before to to convert to int " the line edit string " , so I added a button and a new line edit which is read only , and I wanted it to display x+y when the user clicks " compute " , the problem is it says no such slot for get_sum() and when I press compute after putting two numbers it doesn't show the answer.
here's the header:
@
#ifndef CHECKCLASS_H
#define CHECKCLASS_H
#include<QLabel>
#include<QHBoxLayout>
#include<QLineEdit>
#include<QIntValidator>
#include<QWidget>
#include<QPushButton>
class checkclass : public QWidget
{
Q_OBJECT
public:
checkclass(QWidget *parent=0);private slots:
void convert(); void convert1(); void get_sum(); private: QPushButton *ReturnV; QLineEdit *edit; QLineEdit *edit1; QLineEdit *E; QIntValidator *Valid; QHBoxLayout *left; QHBoxLayout *Main; int x; int y;
};
#endif // CHECKCLASS_H
@here's the imp:
@
#include "checkclass.h"checkclass::checkclass(QWidget *parent):
QWidget(){
Valid=new QIntValidator;
edit = new QLineEdit;
edit1=new QLineEdit;
E=new QLineEdit;
ReturnV=new QPushButton;
ReturnV->setText("Compute");
E->setReadOnly(true);left= new QHBoxLayout; Main=new QHBoxLayout; edit->setMaximumWidth(20); edit->setFixedWidth(20); edit->setValidator(Valid); edit1->setMaximumWidth(20); edit1->setFixedWidth(20); edit1->setValidator(Valid); QObject:: connect(edit,SIGNAL(editingFinished()),this,SLOT(convert())); QObject:: connect(edit1,SIGNAL(editingFinished()),this,SLOT(convert1())); QObject::connect(ReturnV,SIGNAL(clicked()),E,SLOT(get_sum())); left->addWidget(edit); left->addWidget(edit1); left->addWidget(E); left->addWidget(ReturnV); Main->addLayout(left); setLayout(Main);
}
void checkclass::convert(){
QString numbertext=edit->text();
x=numbertext.toInt();}
void checkclass::convert1(){
QString numbertext=edit1->text();
y=numbertext.toInt();}
void checkclass::get_sum(){
int z=x+y;
QString textN= QString::number(z);
E->setText(textN);}
@Thanks in advance.
-
Hi, this line:
QObject::connect(ReturnV,SIGNAL(clicked()),E,SLOT(get_sum()));
try change E to this:
QObject::connect(ReturnV,SIGNAL(clicked()),this,SLOT(get_sum())); -
Ah man thanks it worked , but could you explain why my way didn't work ? please :(
-
Well, it could, but then you have to check, if the E class also has a
slot: void get_sum() declared? -
Ah , thank you ^^