dialog.h
#ifndef DIALOG_H
#define DIALOG_H
#include <QDialog>
namespace Ui {
class Dialog;
}
class Dialog : public QDialog
{
Q_OBJECT
public:
explicit Dialog(QWidget *parent = nullptr);
~Dialog();
private slots:
void on_pushButton_clicked();
void on_lineEdit_textChanged(const QString &arg1);
private:
Ui::Dialog *ui;
};
#endif // DIALOG_H
dialog.cpp
#include "dialog.h"
#include "ui_dialog.h"
const static double PI = 3.1416;
Dialog::Dialog(QWidget *parent)
: QDialog(parent)
, ui(new Ui::Dialog)
{
ui->setupUi(this);
}
Dialog::~Dialog()
{
delete ui;
}
void Dialog::on_pushButton_clicked()
{
bool ok;
QString tempStr;
QString valueStr = ui->lineEdit->text();
int valueInt = valueStr.toInt(&ok);
double area = valueInt* valueInt * PI;
ui->areaLabel_2->setText(tempStr.setNum(area));
}
void Dialog::on_lineEdit_textChanged(const QString &arg1)
{
bool ok;
QString tempStr;
QString valueStr = ui->lineEdit->text();
int valueInt = valueStr.toInt(&ok);
double area = valueInt* valueInt * PI;
ui->areaLabel_2->setText(tempStr.setNum(area));
}
界面文件
结果