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));
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();
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.
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.
I figured it out:
QString XMAX=ui->lineEdit->text();
xMax=XMAX.toDouble();
Or
std::stod(ui->lineEdit->text().toStdString());
but watch out for the encoding.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With