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中显示】
double MainWindow::jisuan(QLineEdit *l){
bool ok;
QString lsnum;
lsnum=l->text();
int num = lsnum.toInt(&ok);
double zuizhongjieguo = num*num*3.14;
return zuizhongjieguo;
}
int MainWindow::jisuanint(QLineEdit *l){
bool ok;
QString lsnum;
lsnum=l->text();
int num = lsnum.toInt(&ok);
double zuizhongjieguo = num*num*3.14;
return zuizhongjieguo;
}
文章来源:https://www.toymoban.com/news/detail-516095.html
【本节代码】文章来源地址https://www.toymoban.com/news/detail-516095.html
#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 = new QLabel(this);
l1->setText("输入圆的面积:");//label类
line = new QLineEdit(this);//这是一个编辑框
//label可以用来显示数字此处决定用linedit显示结果
l2 = new QLabel(this);
jieguo = new QLineEdit(this);
l2->setText("int类型结果");
btn = new QPushButton(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中显示】
double MainWindow::jisuan(QLineEdit *l){
bool ok;
QString lsnum;
lsnum=l->text();
int num = lsnum.toInt(&ok);
double zuizhongjieguo = num*num*3.14;
return zuizhongjieguo;
}
int MainWindow::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;
}
到了这里,关于Qt linedeit中数据的读取和计算的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!