Convert QLineEdit to float
-
Windows 11, Qt Creator 12.0.2 Qt 6.6.0
I am having a difficult time finding this in the documentation. What is a good search term to find this information? Or a link to the information. Or some examples demonstrating how to do this.QLineEdit le_s; // part of mainwindow.ui, here for clarity. float x; // need ability to show max value for float and double double y; x = le_s.get_float(); // need something to this effect y = le_s.get_double(); int count; count = sprint( ( le_s, sizeof( le_s ), “%f”, x ); count = sprint( ( le_s, sizeof( le_s ), “%ff”, x ); // ff standing in for double
Thank you for your time.
Edit: I continued trying, found something, and wrote:void quadratic::load_abc() { QString text; text = le_q_a_input.text(); };
le_q_q_input is the name given to a QLineEdit in file/class quadratic.ui.
Qt Creator states it is an undeclared identifier. This is my first Qt project and I have missed something fundamental. Why is that QLineEdit not found? -
Windows 11, Qt Creator 12.0.2 Qt 6.6.0
I am having a difficult time finding this in the documentation. What is a good search term to find this information? Or a link to the information. Or some examples demonstrating how to do this.QLineEdit le_s; // part of mainwindow.ui, here for clarity. float x; // need ability to show max value for float and double double y; x = le_s.get_float(); // need something to this effect y = le_s.get_double(); int count; count = sprint( ( le_s, sizeof( le_s ), “%f”, x ); count = sprint( ( le_s, sizeof( le_s ), “%ff”, x ); // ff standing in for double
Thank you for your time.
Edit: I continued trying, found something, and wrote:void quadratic::load_abc() { QString text; text = le_q_a_input.text(); };
le_q_q_input is the name given to a QLineEdit in file/class quadratic.ui.
Qt Creator states it is an undeclared identifier. This is my first Qt project and I have missed something fundamental. Why is that QLineEdit not found? -
Windows 11, Qt Creator 12.0.2 Qt 6.6.0
I am having a difficult time finding this in the documentation. What is a good search term to find this information? Or a link to the information. Or some examples demonstrating how to do this.QLineEdit le_s; // part of mainwindow.ui, here for clarity. float x; // need ability to show max value for float and double double y; x = le_s.get_float(); // need something to this effect y = le_s.get_double(); int count; count = sprint( ( le_s, sizeof( le_s ), “%f”, x ); count = sprint( ( le_s, sizeof( le_s ), “%ff”, x ); // ff standing in for double
Thank you for your time.
Edit: I continued trying, found something, and wrote:void quadratic::load_abc() { QString text; text = le_q_a_input.text(); };
le_q_q_input is the name given to a QLineEdit in file/class quadratic.ui.
Qt Creator states it is an undeclared identifier. This is my first Qt project and I have missed something fundamental. Why is that QLineEdit not found?@Bryan-Kelly
Don;t forget what I said in your other email, which is you would be better off using aQSpinBox
/QDoubleSpinBox
for entering numbers than aQLineEdit
. It would do conversions between numbers and strings for you. -
@Bryan-Kelly
Don;t forget what I said in your other email, which is you would be better off using aQSpinBox
/QDoubleSpinBox
for entering numbers than aQLineEdit
. It would do conversions between numbers and strings for you.@JonB OK, looking at that. But have a more fundamental error. Be aware this is my first Qt project.
In file quadratic.ui is a QLineEdit named le_q_a_input.
This might soon be a spin box with that name. To me, that looks like a declared item or variable. I then wrote the following code.void quadratic::load_abc() { QString text; text = le_q_a_input.text(); };
Qt Creator states: Use of undeclared identifier 'le_q_a_input'
What is the fundamental concept I have missed here? -
@JonB OK, looking at that. But have a more fundamental error. Be aware this is my first Qt project.
In file quadratic.ui is a QLineEdit named le_q_a_input.
This might soon be a spin box with that name. To me, that looks like a declared item or variable. I then wrote the following code.void quadratic::load_abc() { QString text; text = le_q_a_input.text(); };
Qt Creator states: Use of undeclared identifier 'le_q_a_input'
What is the fundamental concept I have missed here?@Bryan-Kelly
You don't have any variable namedle_q_a_input
, simple as. If you created it in Designer, and that's its name, it's likely to be inui
, soui->le_q_a_input
. All widgets in Designer go intoui
. -
@Bryan-Kelly
You don't have any variable namedle_q_a_input
, simple as. If you created it in Designer, and that's its name, it's likely to be inui
, soui->le_q_a_input
. All widgets in Designer go intoui
.@JonB I am missing some real important, or am describing the situation badly. Begin with a simple project: Application(Qt) -> Qt Widgets Application.
Add a new dialog with: File -> New File -> Qt Qt Designer Form Class. Name the class quadratic.
Qt Creator creates the files: quadratic.h, quadratic.cpp, and quadratic.ui. Open quadratic.ui and drop a tool on it named le_q_a_input.I expect to be able to access the tool with something like:
void quadratic::load_abc(){ QString text; text = le_q_a_input->text(); // or maybe ... input.text() }
Qt Creator states undeclared identifier.
I am working on the Spin Box and Double Spin Box, but am confident the question will remain the same.
I don't understand why you would write there is no variable by that name.
Edit: when quadratic.ui is open, and the line edit item has been selected, the properties dialog (name??) has this at its top.
I interpret that as a clear statement that the object by that name does indeed exist. So, how do I access it in code? -
@JonB I am missing some real important, or am describing the situation badly. Begin with a simple project: Application(Qt) -> Qt Widgets Application.
Add a new dialog with: File -> New File -> Qt Qt Designer Form Class. Name the class quadratic.
Qt Creator creates the files: quadratic.h, quadratic.cpp, and quadratic.ui. Open quadratic.ui and drop a tool on it named le_q_a_input.I expect to be able to access the tool with something like:
void quadratic::load_abc(){ QString text; text = le_q_a_input->text(); // or maybe ... input.text() }
Qt Creator states undeclared identifier.
I am working on the Spin Box and Double Spin Box, but am confident the question will remain the same.
I don't understand why you would write there is no variable by that name.
Edit: when quadratic.ui is open, and the line edit item has been selected, the properties dialog (name??) has this at its top.
I interpret that as a clear statement that the object by that name does indeed exist. So, how do I access it in code?@Bryan-Kelly
You write the same again. I said Designer puts all created widgets intoui
. I suggested what you try. Did you read and do so?
Yes it will be same issue no matter which widget type. -
@JonB I am missing some real important, or am describing the situation badly. Begin with a simple project: Application(Qt) -> Qt Widgets Application.
Add a new dialog with: File -> New File -> Qt Qt Designer Form Class. Name the class quadratic.
Qt Creator creates the files: quadratic.h, quadratic.cpp, and quadratic.ui. Open quadratic.ui and drop a tool on it named le_q_a_input.I expect to be able to access the tool with something like:
void quadratic::load_abc(){ QString text; text = le_q_a_input->text(); // or maybe ... input.text() }
Qt Creator states undeclared identifier.
I am working on the Spin Box and Double Spin Box, but am confident the question will remain the same.
I don't understand why you would write there is no variable by that name.
Edit: when quadratic.ui is open, and the line edit item has been selected, the properties dialog (name??) has this at its top.
I interpret that as a clear statement that the object by that name does indeed exist. So, how do I access it in code?@Bryan-Kelly said in Convert QLineEdit to float:
I interpret that as a clear statement that the object by that name does indeed exist. So, how do I access it in code?
I answered. And all examples show that. Why not work through samples provided by Qt, it's really useful at your stage.
-
@Bryan-Kelly
You write the same again. I said Designer puts all created widgets intoui
. I suggested what you try. Did you read and do so?
Yes it will be same issue no matter which widget type.@JonB said in Convert QLineEdit to float:
@Bryan-Kelly
You write the same again. I said Designer puts all created widgets intoui
. I suggested what you try. Did you read and do so?
Yes it will be same issue no matter which widget type.I don't understand the meaning of the statement that Designer puts all the created widgets into 'ui'. Seems to me I am using Designer when I open quadratic.ui and drop tools onto the dialog.
-
@Bryan-Kelly
You don't have any variable namedle_q_a_input
, simple as. If you created it in Designer, and that's its name, it's likely to be inui
, soui->le_q_a_input
. All widgets in Designer go intoui
. -
@JonB I am missing some real important, or am describing the situation badly. Begin with a simple project: Application(Qt) -> Qt Widgets Application.
Add a new dialog with: File -> New File -> Qt Qt Designer Form Class. Name the class quadratic.
Qt Creator creates the files: quadratic.h, quadratic.cpp, and quadratic.ui. Open quadratic.ui and drop a tool on it named le_q_a_input.I expect to be able to access the tool with something like:
void quadratic::load_abc(){ QString text; text = le_q_a_input->text(); // or maybe ... input.text() }
Qt Creator states undeclared identifier.
I am working on the Spin Box and Double Spin Box, but am confident the question will remain the same.
I don't understand why you would write there is no variable by that name.
Edit: when quadratic.ui is open, and the line edit item has been selected, the properties dialog (name??) has this at its top.
I interpret that as a clear statement that the object by that name does indeed exist. So, how do I access it in code?@Bryan-Kelly said in Convert QLineEdit to float:
Qt Creator states undeclared identifier.
Go to the
private
section ofquadratic.h
...
Most likely you have a variable calledUi::quadratic *ui
there.
THIS is (the pointer to) your compiled user interface class (made byuic
fromquadratic.ui
).
The Qt user interface compiler (uic) translated your XXXX.ui file, which is some kind of XML style file to a usable C/C++ header.
And THIS class is used asui
object/variable in yourquadratic.h
/quadratic.cpp
class.So your
le_q_a_input
is NOT accessible directly, because it's part of the translated UI file.
Therefore you can reach it by using the pointer to your UI, i.e.ui->"objectname"
.This is what @JonB said here:
@JonB said in Convert QLineEdit to float:
I said Designer puts all created widgets into ui
-
@JonB said in Convert QLineEdit to float:
so
ui->le_q_a_input
Did you try this? You only have to copy and paste it.
@JonB Now I have this
void quadratic::load_abc() { QString text; text = ui->le_q_a_input->text(); ...
That seems to be accepted.
I just could not see what you were after.
Now to go for the spin tool.
Thank you for your patience. -
@JonB Now I have this
void quadratic::load_abc() { QString text; text = ui->le_q_a_input->text(); ...
That seems to be accepted.
I just could not see what you were after.
Now to go for the spin tool.
Thank you for your patience.I can only recommend you to read these first:
Basic project setup:
- https://doc.qt.io/qt-6/designer-using-a-ui-file.html
- https://doc.qt.io/qtcreator/creator-writing-program.html
Qt specific things you should know:
- https://doc.qt.io/qt-6/metaobjects.html
- https://doc.qt.io/qt-6/objecttrees.html
- https://doc.qt.io/qt-6/signalsandslots.html
- https://doc.qt.io/qt-6/eventsandfilters.html
Knowing this (not perfectly) in combination with a solid C++ skill level is a good start.