#include <QApplication>
#include <QPushButton>
#include <QLabel>
#include <QSpinBox>
#include <QLCDNumber>
#include <QHBoxLayout>
#include <QVBoxLayout>
class Calculator
: public QWidget { Q_OBJECT
public:
layout->addWidget(num1);
layout->addWidget(minus);
layout->addWidget(num2);
layout->addWidget(answer);
buttons->addStretch();
buttons->addWidget(equal);
buttons->addStretch();
mainLayout->addLayout(layout);
mainLayout->addLayout(buttons);
QObject::connect(equal,
SIGNAL(clicked
()), answer,
SLOT(calculate
()));
}
public slots:
void calculate() {
answer->display(num1->value()-num2->value());
disconnect();
}
private:
};
int main(int argc, char **argv){
Calculator w;
w.show();
return app.exec();
}
#include <QApplication>
#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 QLabel("-");
equal = new QPushButton("&Execute");
num1 = new QSpinBox;
num2 = new QSpinBox;
answer = new QLCDNumber(3);
QHBoxLayout *layout = new QHBoxLayout;
layout->addWidget(num1);
layout->addWidget(minus);
layout->addWidget(num2);
layout->addWidget(answer);
QHBoxLayout *buttons = new QHBoxLayout;
buttons->addStretch();
buttons->addWidget(equal);
buttons->addStretch();
QVBoxLayout *mainLayout = new QVBoxLayout(this);
mainLayout->addLayout(layout);
mainLayout->addLayout(buttons);
QObject::connect(equal, SIGNAL(clicked()), answer, SLOT(calculate()));
}
public slots:
void calculate() {
answer->display(num1->value()-num2->value());
disconnect();
}
private:
QLabel *minus;
QPushButton *equal;
QPushButton *help;
QSpinBox *num1;
QSpinBox *num2;
QLCDNumber *answer;
};
int main(int argc, char **argv){
QApplication app(argc, argv);
Calculator w;
w.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
When the compiler is linking to the .exe it gives me this error.
C:\Program Files\CodeBlocks\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\include\c++\3.4.5\bits\stl_algobase.h:(.text$_ZN10CalculatorD1Ev[Calculator::~Calculator()]+0xb)||undefined reference to `vtable for Calculator'|
C:\Program Files\CodeBlocks\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\include\c++\3.4.5\bits\stl_algobase.h:(.text$_ZN10CalculatorD1Ev[Calculator::~Calculator()]+0xb)||undefined reference to `vtable for Calculator'|
To copy to clipboard, switch view to plain text mode
Thank you in advance.
Bookmarks