wait... now I changed the code up a bit and I think need to update the .moc file but can't find out how
he is main.cpp
#include <QApplication>
#include "calc.h"
int main(int argc, char **argv){
Calculator w;
w.show();
return app.exec();
}
#include "main.moc"
#include <QApplication>
#include "calc.h"
int main(int argc, char **argv){
QApplication app(argc, argv);
Calculator w;
w.show();
return app.exec();
}
#include "main.moc"
To copy to clipboard, switch view to plain text mode
and calc.h
#ifndef CALC_H
#define CALC_H
#include <QPushButton>
#include <QLabel>
#include <QSpinBox>
#include <QLCDNumber>
#include <QHBoxLayout>
#include <QVBoxLayout>
class Calculator
: public QWidget { Q_OBJECT
public:
layout->addWidget(num1);
layout->addWidget(num2);
layout->addWidget(answer);
button1->addStretch();
button1->addWidget(add);
button1->addWidget(minus);
button1->addStretch();
button2->addStretch();
button2->addWidget(multiply);
button2->addWidget(divide);
button2->addStretch();
mainLayout->addLayout(layout);
mainLayout->addLayout(button1);
mainLayout->addLayout(button2);
connect(minus, SIGNAL(clicked()), this, SLOT(subtract()));
}
public slots:
void subtract(){
answer->display(num1->value()-num2->value());
disconnect();
}
void plus(){
answer->display(num1->value()+num2->value());
}
void times(){
answer->display(num1->value()*num2->value());
}
void divider(){
answer->display(num1->value()/num2->value());
}
private:
};
#endif CALC_H
#ifndef CALC_H
#define CALC_H
#include <QPushButton>
#include <QLabel>
#include <QSpinBox>
#include <QLCDNumber>
#include <QHBoxLayout>
#include <QVBoxLayout>
class Calculator : public QWidget {
Q_OBJECT
public:
Calculator(QWidget *parent = 0) : QWidget(parent){
minus = new QPushButton("&-");
add = new QPushButton("&+");
multiply = new QPushButton("&X");
divide = new QPushButton("&/");
num1 = new QSpinBox;
num2 = new QSpinBox;
answer = new QLCDNumber(3);
QHBoxLayout *layout = new QHBoxLayout;
layout->addWidget(num1);
layout->addWidget(num2);
layout->addWidget(answer);
QHBoxLayout *button1 = new QHBoxLayout;
button1->addStretch();
button1->addWidget(add);
button1->addWidget(minus);
button1->addStretch();
QHBoxLayout *button2 = new QHBoxLayout;
button2->addStretch();
button2->addWidget(multiply);
button2->addWidget(divide);
button2->addStretch();
QVBoxLayout *mainLayout = new QVBoxLayout(this);
mainLayout->addLayout(layout);
mainLayout->addLayout(button1);
mainLayout->addLayout(button2);
connect(minus, SIGNAL(clicked()), this, SLOT(subtract()));
}
public slots:
void subtract(){
answer->display(num1->value()-num2->value());
disconnect();
}
void plus(){
answer->display(num1->value()+num2->value());
}
void times(){
answer->display(num1->value()*num2->value());
}
void divider(){
answer->display(num1->value()/num2->value());
}
private:
QPushButton *minus;
QPushButton *add;
QPushButton *multiply;
QPushButton *divide;
QPushButton *help;
QSpinBox *num1;
QSpinBox *num2;
QLCDNumber *answer;
};
#endif CALC_H
To copy to clipboard, switch view to plain text mode
Bookmarks