I have created a programme with following files
calculator.cpp
#include "calculator.h"
#include "ui_calculator.h"
calculator
::calculator(QWidget *parent
){
//Ui::calculatorClass *cal = new Ui::calculatorClass;
//ui.setupUi(cal);
ui.setupUi(this);
connect (ui.spinBox1, SIGNAL(valueChanged(int)), this, SLOT(setValueLineEditSpinBox1(int & value)));
/* connect (ui.spinBox2, SIGNAL(valueChanged(int)), calculator, SLOT(setValueLineEditSpinBox2(int & value))); */
ui.lineEdit->setText("5");
}
calculator::~calculator()
{
}
//slots
void calculator::setValueLineEditSpinBox1(int &value)
{
ui.
lineEdit->setText
(QString::number(value
+ui.
spinBox2->value
()));
}
void calculator::setValueLineEditSpinBox2(int &value)
{
ui.
lineEdit->setText
(QString::number(value
+ui.
spinBox1->value
()));
}
#include "calculator.h"
#include "ui_calculator.h"
calculator::calculator(QWidget *parent)
: QWidget(parent)
{
//Ui::calculatorClass *cal = new Ui::calculatorClass;
//ui.setupUi(cal);
ui.setupUi(this);
connect (ui.spinBox1, SIGNAL(valueChanged(int)), this, SLOT(setValueLineEditSpinBox1(int & value)));
/* connect (ui.spinBox2, SIGNAL(valueChanged(int)), calculator, SLOT(setValueLineEditSpinBox2(int & value))); */
ui.lineEdit->setText("5");
}
calculator::~calculator()
{
}
//slots
void calculator::setValueLineEditSpinBox1(int &value)
{
ui.lineEdit->setText(QString::number(value+ui.spinBox2->value()));
}
void calculator::setValueLineEditSpinBox2(int &value)
{
ui.lineEdit->setText(QString::number(value+ui.spinBox1->value()));
}
To copy to clipboard, switch view to plain text mode
calculator. h file
#ifndef CALCULATOR_H
#define CALCULATOR_H
#include <QtGui/QWidget>
#include "ui_calculator.h"
{
Q_OBJECT
public:
~calculator();
signals:
/* int valuespinBox1();
int valuespinBox2();
*/
public slots:
void setValueLineEditSpinBox1(int &value);
void setValueLineEditSpinBox2(int &value);
private:
Ui::calculatorClass ui;
};
#endif // CALCULATOR_H
#ifndef CALCULATOR_H
#define CALCULATOR_H
#include <QtGui/QWidget>
#include "ui_calculator.h"
class calculator : public QWidget
{
Q_OBJECT
public:
calculator(QWidget *parent = 0);
~calculator();
signals:
/* int valuespinBox1();
int valuespinBox2();
*/
public slots:
void setValueLineEditSpinBox1(int &value);
void setValueLineEditSpinBox2(int &value);
private:
Ui::calculatorClass ui;
};
#endif // CALCULATOR_H
To copy to clipboard, switch view to plain text mode
main.cpp file
#include "calculator.h"
#include "ui_calculator.h"
#include <QtGui>
#include <QApplication>
int main(int argc, char *argv[])
{
calculator w;
w.show();
return a.exec();
}
#include "calculator.h"
#include "ui_calculator.h"
#include <QtGui>
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
calculator w;
w.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
I get an error as below
No symbol "auto" in current context.
warning: Object::connect: No such slot calculator::setValueLineEditSpinBox1(int&value)
warning: Object::connect: (sender name: 'spinBox1')
warning: Object::connect: (receiver name: 'calculatorClass'
what is the issue in signal and slot not able to understand
can anybody help please?
Bookmarks