#include<QtGui>
#include"dencaler.h"
{
setupUi(this);
//make lineedits only accepte a certain double
knownTemperatureLineEdit
->setValidator
(new QDoubleValidator(15.0,
101.0,
2,knownTemperatureLineEdit
));
knowDensityLineEdit
->setValidator
(new QDoubleValidator(0.1,
1.2,
2,knowDensityLineEdit
));
// Are the above Validators OK? I found that they couldn't work properly. They can accept numbers like this:10000.0.
// I just want the first lineEdit to accept double 15.00~101.00
// and the second lineEdit to accept double range 0.10~1.20
//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());
// Only the two lineEdit get proper numbers can enable the OK button.
}
void Dencaler::update()
{
//implement calculation for the dialog
double val1=(knownTemperatureLineEdit->text()).toDouble();
double val2=(knowDensityLineEdit->text()).toDouble();
double sum=val1+val2;
// Implement plus to simulate data transformation.
char str[8];
sprintf(str,"%f",sum);
sprintf(str,"%f",sum+0.3);
//Update date in the dialog.
}
#include<QtGui>
#include"dencaler.h"
Dencaler::Dencaler(QWidget *parent):QDialog(parent)
{
setupUi(this);
//make lineedits only accepte a certain double
knownTemperatureLineEdit->setValidator(new QDoubleValidator(15.0,101.0,2,knownTemperatureLineEdit));
knowDensityLineEdit->setValidator(new QDoubleValidator(0.1,1.2,2,knowDensityLineEdit));
// Are the above Validators OK? I found that they couldn't work properly. They can accept numbers like this:10000.0.
// I just want the first lineEdit to accept double 15.00~101.00
// and the second lineEdit to accept double range 0.10~1.20
//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());
// Only the two lineEdit get proper numbers can enable the OK button.
}
void Dencaler::update()
{
//implement calculation for the dialog
double val1=(knownTemperatureLineEdit->text()).toDouble();
double val2=(knowDensityLineEdit->text()).toDouble();
double sum=val1+val2;
// Implement plus to simulate data transformation.
char str[8];
sprintf(str,"%f",sum);
label20->setText(QString(str));
sprintf(str,"%f",sum+0.3);
label15->setText(QString(str));
QDialog::update();
//Update date in the dialog.
}
To copy to clipboard, switch view to plain text mode
Bookmarks