Thanks, this problem is solved, but now come other problems.
calc.h:18: error: ISO C++ forbids declaration of ‘QLCDNumber’ with no type
calc.h:18: error: expected ‘;’ before ‘*’ token
So I added the declaration of QLCDNumber class: class QLCDNumber;. and now are problems with the inside of the slot:
calc.cpp:17: error: invalid use of member (did you forget the ‘&’ ?)
How can I solve it?
I think i solve this problem. I add to class Calc new variable int value, which stores the actual result of calculations and use display function.
But... I have new problem...
Here is my source code:
//calc.h
#ifndef CALC_H
#define CALC_H
#include <QtGui/QDialog>
namespace Ui
{
class Calc;
}
{
Q_OBJECT
private:
int value;
public:
~Calc();
public slots:
void setVal(const int &val);
private:
Ui::Calc *ui;
};
#endif // CALC_H
//calc.h
#ifndef CALC_H
#define CALC_H
#include <QtGui/QDialog>
class QLCDNumber;
namespace Ui
{
class Calc;
}
class Calc : public QDialog
{
Q_OBJECT
private:
QLCDNumber *lcdNumber;
QPushButton *seventhButton;
QPushButton *eighthButton;
QPushButton *ninethButton;
QPushButton *divisionButton;
QPushButton *fourthButton;
QPushButton *fifthButton;
QPushButton *sixthButton;
QPushButton *additionButton;
QPushButton *firstButton;
QPushButton *secondButton;
QPushButton *thirdButton;
QPushButton *subtractionButton;
QPushButton *zeroButton;
QPushButton *sqrtButton;
QPushButton *multiplicationButton;
QPushButton *moduloButton;
int value;
public:
Calc(QWidget *parent = 0);
~Calc();
public slots:
void setVal(const int &val);
private:
Ui::Calc *ui;
};
#endif // CALC_H
To copy to clipboard, switch view to plain text mode
#include "calc.h"
#include "ui_calc.h"
: QDialog(parent
), ui
(new Ui
::Calc) {
ui->setupUi(this);
connect(zeroButton, SIGNAL(clicked()), this, SLOT(setVal(0)));
}
Calc::~Calc()
{
delete ui;
}
void Calc::setVal(const int &val){
value*=10;
value+=val;
lcdNumber ->display(value);
}
#include "calc.h"
#include "ui_calc.h"
Calc::Calc(QWidget *parent)
: QDialog(parent), ui(new Ui::Calc)
{
ui->setupUi(this);
connect(zeroButton, SIGNAL(clicked()), this, SLOT(setVal(0)));
}
Calc::~Calc()
{
delete ui;
}
void Calc::setVal(const int &val){
value*=10;
value+=val;
lcdNumber ->display(value);
}
To copy to clipboard, switch view to plain text mode
In the constructor I add the conection between zero button and LCDNumber. It should works, but in the console are errors:
I have no idea how to do this. Could anyone help me?
It's harder than I thought at the beginning of lessons.
I've read in documentation that the signal and slot parameters mustn't contain variable name, but only type, so how can I send the value, which is needed?
Bookmarks