leble和linedeit的数据显示是相同的
【数据显示】
connect(btn,&QPushButton::clicked,this,[=](){
QString meijie;
jieguo->setText(meijie.setNum(jisuan(line)));
l2->setText(meijie.setNum(jisuanint(line)));});
【数据计算】
//获取lineedit或label中的数据并在linedeit中显示【一般在label中显示】doubleMainWindow::jisuan(QLineEdit *l){bool ok;
QString lsnum;
lsnum=l->text();int num = lsnum.toInt(&ok);double zuizhongjieguo = num*num*3.14;return zuizhongjieguo;}intMainWindow::jisuanint(QLineEdit *l){bool ok;
QString lsnum;
lsnum=l->text();int num = lsnum.toInt(&ok);double zuizhongjieguo = num*num*3.14;return zuizhongjieguo;}
【本节代码】
#include"mainwindow.h"#include"ui_mainwindow.h"#include<QGridLayout>//布局管理器MainWindow::MainWindow(QWidget *parent):QMainWindow(parent),ui(new Ui::MainWindow){setFixedSize(400,200);
ui->setupUi(this);
l1 =newQLabel(this);
l1->setText("输入圆的面积:");//label类
line =newQLineEdit(this);//这是一个编辑框//label可以用来显示数字此处决定用linedit显示结果
l2 =newQLabel(this);
jieguo =newQLineEdit(this);
l2->setText("int类型结果");
btn =newQPushButton(this);
btn->setText("计算结果是");
l1->move(0,0);
line->move(100,0);
btn->move(0,100);
jieguo->move(100,100);
l2->move(200,100);connect(btn,&QPushButton::clicked,this,[=](){
QString meijie;
jieguo->setText(meijie.setNum(jisuan(line)));
l2->setText(meijie.setNum(jisuanint(line)));});}//获取lineedit或label中的数据并在linedeit中显示【一般在label中显示】doubleMainWindow::jisuan(QLineEdit *l){bool ok;
QString lsnum;
lsnum=l->text();int num = lsnum.toInt(&ok);double zuizhongjieguo = num*num*3.14;return zuizhongjieguo;}intMainWindow::jisuanint(QLineEdit *l){bool ok;
QString lsnum;
lsnum=l->text();int num = lsnum.toInt(&ok);double zuizhongjieguo = num*num*3.14;return zuizhongjieguo;}MainWindow::~MainWindow(){delete ui;}
本文转载自: https://blog.csdn.net/weixin_45646601/article/details/126320525
版权归原作者 蔡徐坤学C++ 所有, 如有侵权,请联系我们删除。
版权归原作者 蔡徐坤学C++ 所有, 如有侵权,请联系我们删除。