It's my fault to express my views.
With your help, I had corrected my code in this way:
#include<QtGui>
#include"dencaler.h"
#include"QPersonalDoubleValidator.h"
{
setupUi(this);
//make lineedits only accepte a certain double
knownTemperatureLineEdit->setValidator(new QPersonalDoubleValidator(15.0,101.0,2,knownTemperatureLineEdit));
knowDensityLineEdit->setValidator(new QPersonalDoubleValidator(0.1,1.2,2,knowDensityLineEdit));
//connect sigal to slot to make update available
connect(okButton, SIGNAL(clicked()), this, SLOT(update()));
}
void Dencaler::on_knowDensityLineEdit_textChanged()
{
okButton->setEnabled(knownTemperatureLineEdit->hasAcceptableInput()&&knowDensityLineEdit->hasAcceptableInput());
}
void Dencaler::update()
{
//implement calculation for the dialog
double val1=(knownTemperatureLineEdit->text()).toDouble();
double val2=(knowDensityLineEdit->text()).toDouble();
double sum=val1+val2;
label20
->setText
(QString::number(sum
));
sum+=0.3;
label15
->setText
(QString::number(sum
));
}
#include<QtGui>
#include"dencaler.h"
#include"QPersonalDoubleValidator.h"
Dencaler::Dencaler(QWidget *parent):QDialog(parent)
{
setupUi(this);
//make lineedits only accepte a certain double
knownTemperatureLineEdit->setValidator(new QPersonalDoubleValidator(15.0,101.0,2,knownTemperatureLineEdit));
knowDensityLineEdit->setValidator(new QPersonalDoubleValidator(0.1,1.2,2,knowDensityLineEdit));
//connect sigal to slot to make update available
connect(okButton, SIGNAL(clicked()), this, SLOT(update()));
}
void Dencaler::on_knowDensityLineEdit_textChanged()
{
okButton->setEnabled(knownTemperatureLineEdit->hasAcceptableInput()&&knowDensityLineEdit->hasAcceptableInput());
}
void Dencaler::update()
{
//implement calculation for the dialog
double val1=(knownTemperatureLineEdit->text()).toDouble();
double val2=(knowDensityLineEdit->text()).toDouble();
double sum=val1+val2;
label20->setText(QString::number(sum));
sum+=0.3;
label15->setText(QString::number(sum));
QDialog::update();
}
To copy to clipboard, switch view to plain text mode
But that's still a problem.
I intend to use the two number input in the QLineEdits to implement some caculation and then set the results in two labels to display them. I wrote the action in an overloaded update(), but i doesn't work. the code post as follow:
void Dencaler::update()
{
//implement calculation for the dialog
double val1=(knownTemperatureLineEdit->text()).toDouble();
double val2=(knowDensityLineEdit->text()).toDouble();
double sum=val1+val2;
label20
->setText
(QString::number(sum
));
sum+=0.3;
label15
->setText
(QString::number(sum
));
}
void Dencaler::update()
{
//implement calculation for the dialog
double val1=(knownTemperatureLineEdit->text()).toDouble();
double val2=(knowDensityLineEdit->text()).toDouble();
double sum=val1+val2;
label20->setText(QString::number(sum));
sum+=0.3;
label15->setText(QString::number(sum));
QDialog::update();
}
To copy to clipboard, switch view to plain text mode
Bookmarks