C++ 从 QLineEdit 获取值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12161082/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 15:57:20  来源:igfitidea点击:

Get the value from a QLineEdit

c++qlineedit

提问by SamuelNLP

I have a QLineEditthat only allows numbers and I want to get the current value from it. I can't figure out how.

我有一个QLineEdit只允许数字,我想从中获取当前值。我无法弄清楚如何。

ui->lineEdit->setValidator(new QIntValidator(this));

回答by SamuelNLP

I figured it out:

我想到了:

QString XMAX=ui->lineEdit->text();
xMax=XMAX.toDouble();

回答by g24l

Or

或者

std::stod(ui->lineEdit->text().toStdString());

but watch out for the encoding.

但要注意编码。

回答by Samuel Ives

Try this:

尝试这个:

ui->leNome->displayText()