Habe seit 1 woche die Aufgabe mit dem QT ein Mainwindow zu erstellen, dass 3 Zahlen zusammenrechnet und ausgibt. (ich muss gestehen, dass ich neu auf dem Gebiet bin)
ich habe es geschafft das erste Feld abzuprüfen und eine Fehlermeldung auszugeben wenn keine gültige Zahl eingegeben wurde.
Jetzt komme ich leider nicht weiter.
MainWindow.cpp
Code: Alles auswählen
#include <QtGui>
#include "MainWindow.h"
MainWindow::MainWindow(QMainWindow *parent)
:QMainWindow(parent)
{
setupUi(this);
connect(calcPB, SIGNAL(clicked()), this, SLOT(calc()));
connect(output,SIGNAL(clicked()), this, SLOT(showErg()));
}
void MainWindow::calc() {
int zahl_1=0 ,zahl_2=0, zahl_3=0;
// int erg=0;
bool ok=false;
zahl_1 = input_1->text().toInt(&ok);
// zahl_2 = input_2->text().toInt(&ok);
// zahl_3 = input_3->text().toInt(&ok);
if(ok==false){
showConvError (input_1->text(),QString("1"))
}else {
qDebug()<<"alles Ok";
}
}
void MainWindow::showConvError(const QString & value, const QString & inputNumber ){
QMessageBox::warning(this, "Warnung", "Der von Ihnen eingegebene Wert \"" + value + "\" im Feld \"" + inputNumber + "\" ist ungueltig.");
}
//void MainWindow::showErg(const QString & value ){
//QLineEdit erg;
//erg.input_1->text();
//}Code: Alles auswählen
MainWindow.h
//}#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include "ui_MainWindow.h"
class MainWindow : public QMainWindow , private Ui::MainWindow
{
Q_OBJECT
public:
MainWindow(QMainWindow *parent=0);
public slots:
void calc();
void showConvError(const QString &, const QString & );
void showErg(const QString &);
};
#endifCode: Alles auswählen
Main.cpp
#include <QApplication>
#include "MainWindow.h"
int main(int argc, char *argv[])
{
QApplication app(argc,argv);
MainWindow mw;
mw.show();
return app.exec();
}Kann mir bitte jemand weiterhelfen??
lg
nici
Code: Alles auswählen
Code: Alles auswählen