bin neu in der qt-szene
hab mit hilfe eines tutorials mal einen taschenrechner erstellt:
rechner.h:
Code: Alles auswählen
#ifndef TASCHENRECHNER_H
#define TASCHENRECHNER_H
#include <QWIDGET>
class rechner : public QWidget{
Q_OBJECT
public:
rechner(QWidget *parent = 0);
private slots:
void addieren();
};
#endifCode: Alles auswählen
#include "rechner.h"
#include <QLABEL>
#include <QLINEEDIT>
#include <QPUSHBUTTON>
#include <QGRIDLAYOUT>
rechner::rechner (QWidget *parent)
: QWidget (parent)
{
QLabel *labela = new QLabel;
labela -> setText ("variable a");
QLabel *labelb = new QLabel;
labelb -> setText ("variable b");
QLabel *labelc = new QLabel;
labelc -> setText ("a + b =");
QLineEdit *inputa = new QLineEdit;
inputa -> setText ("0");
QLineEdit *inputb = new QLineEdit;
inputb -> setText ("0");
QLineEdit *inputc = new QLineEdit;
QPushButton *calculate = new QPushButton;
calculate -> setText ("aktion");
connect(calculate, SIGNAL(clicked()), inputc, SLOT(addieren()));
QGridLayout *grid = new QGridLayout;
grid -> addWidget (labela, 0, 0);
grid -> addWidget (labelb, 1, 0);
grid -> addWidget (labelc, 2, 0);
grid -> addWidget (inputa, 0, 1);
grid -> addWidget (inputb, 1, 1);
grid -> addWidget (inputc, 2, 1);
grid -> addWidget (calculate, 3, 1);
setLayout (grid);
}
void rechner::addieren () {
double a, b;
a = (inputa -> text ()).toDouble ();
b = (inputb -> text ()).toDouble ();
inputc -> setText (QString ("%1").arg (a+b,0,'f',4));
}Code: Alles auswählen
#include "rechner.h"
#include <QApplication>
int main( int argc, char* argv[]){
QApplication a(argc, argv);
rechner w;
w.show();
return a.exec();
}was mach ich falsch?