guys i need help with my program.if i run this code its crashing.
if there is a value in my QLineEdit the button BMIINTERPRETATION must activate, i set it like this( bimout->setDown(true)) so here is my code. i don't know where i am going wrong any help will be appreciated.thanx
#ifndef BMICAL_H
#define BMICAL_H
#include <QWidget>
#include <QGridLayout>
#include <QSpinBox>
#include <QLabel>
#include <QPushButton>
#include <QLineEdit>
#include <QRadioButton>
#include<QMessageBox>
#include <QApplication>
class bmiCal : public QWidget {
Q_OBJECT
public:
bmiCal();
public slots:
void calculateBmi();
void clear();
void bmiinter();
void makeButtonEnabled(const QString &);
private:
QDoubleSpinBox* heightEntry;
QDoubleSpinBox* weightEntry;
QLineEdit* result;
QPushButton * bimout;
QPushButton * calculate;
QRadioButton * kilograms;
QRadioButton * meters;
QRadioButton * centimeters;
QRadioButton * pounds;
};
#endif // BMICAL_H
#include "bmiCal.h"
bmiCal::bmiCal(){
setWindowTitle("BMI Calculator");
QGridLayout* layout = new QGridLayout(this);
QLabel* inputWeightRequest = new QLabel("Enter weight in kilograms ");
weightEntry = new QDoubleSpinBox();
QLabel* inputHeightRequest = new QLabel("Enter height in meters ");
heightEntry = new QDoubleSpinBox();
QPushButton* calculate = new QPushButton("Calculate");
QPushButton*bimout = new QPushButton("BMIInterpretation");
bimout->setDown(true);
QApplication::processEvents();
QLabel* labelBmi = new QLabel("BMI ");
result = new QLineEdit();
QPushButton* clear = new QPushButton("Clear All");
QRadioButton *kilograms = new QRadioButton(tr("&kilograms "));
kilograms->setChecked(true);
QRadioButton *meters = new QRadioButton(tr("&meters"));
meters->setChecked(true);
QRadioButton *pounds = new QRadioButton(tr("Rapounds"));
QRadioButton *centimeters = new QRadioButton(tr("centimeters"));
layout->addWidget(inputWeightRequest, 0,0);
layout->addWidget(weightEntry, 0,1);
layout->addWidget(inputHeightRequest, 1,0);
layout->addWidget(heightEntry, 1,1);
layout->addWidget(kilograms, 0,3);
layout->addWidget(pounds, 0,4);
layout->addWidget(centimeters, 1,4);
layout->addWidget(meters, 1,3);
layout->addWidget(calculate, 2,1);
layout->addWidget(bimout,3,3);
layout->addWidget(labelBmi,3,0);
layout->addWidget(result,3,1);
layout->addWidget(clear, 4,1);
this->setLayout(layout);
result->setReadOnly(true);
connect(calculate, SIGNAL(clicked()), this, SLOT(calculateBmi()));
connect (clear,SIGNAL(clicked()), this, SLOT(clear()));
connect (bimout,SIGNAL(clicked()),this,SLOT(bmiinter()));
connect(result,SIGNAL(textChanged(const QString &)),this,SLOT(makeButtonEnabled()));
}
void bmiCal::calculateBmi() {
double wStr = weightEntry->value();
double hStr = heightEntry->value();
double bmi= wStr/(hStr*hStr);
if (result>=0) {
result->setText(QString::number(bmi));
}
}
void bmiCal::makeButtonEnabled(){
bimout->setDown(false);
}
void bmiCal::bmiinter(){
QString res=result->text();
double res_nw=res.toDouble();
if (res_nw<18.5){
QMessageBox::information(this,"IBM INTERPRETATION", "Underweight");
}
if (res_nw>=18.5 && res_nw<=25){
QMessageBox::information(this,"IBM INTERPRETATION", "Healthy Weight");
}
if (res_nw>25 && res_nw<30){
QMessageBox::information(this,"IBM INTERPRETATION", "Overweight");
}
if (res_nw>=30){
QMessageBox::information(this,"IBM INTERPRETATION", "Obese");
}
}
void bmiCal::clear(){
weightEntry->clear();
heightEntry->clear();
result->clear();
}