Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the value from a QLineEdit

Tags:

c++

qlineedit

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

ui->lineEdit->setValidator(new QIntValidator(this));
like image 335
SamuelNLP Avatar asked Aug 28 '12 14:08

SamuelNLP


People also ask

How can I get data from line edit in Qt?

So in our Qt widget application, we have the lineEdit element and a pushbutton whose name is "pushButton". The retrieval of the value of the lineEdit element is done when the push button is clicked. So inside of this clicked function, we specify the variable, textvalue, and set it equal to, ui->lineEdit->displayText();

What is QLineEdit in Python?

QLineEdit : It allows the user to enter and edit a single line of plain text with a useful collection of editing functions, including undo and redo, cut and paste, and drag and drop.

How to set text in QLineEdit?

You can change the text with setText() or insert() . The text is retrieved with text() ; the displayed text (which may be different, see EchoMode ) is retrieved with displayText() . Text can be selected with setSelection() or selectAll() , and the selection can be cut() , copy() ied and paste() d.


2 Answers

I figured it out:

QString XMAX=ui->lineEdit->text();
xMax=XMAX.toDouble();
like image 136
SamuelNLP Avatar answered Oct 07 '22 22:10

SamuelNLP


Or

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

but watch out for the encoding.

like image 2
g24l Avatar answered Oct 07 '22 21:10

g24l