Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Convert QLineEdit to float
Forum Updated to NodeBB v4.3 + New Features

Convert QLineEdit to float

Scheduled Pinned Locked Moved Unsolved General and Desktop
13 Posts 4 Posters 1.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Bryan Kelly
    wrote on last edited by Bryan Kelly
    #1

    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?

    Christian EhrlicherC JonBJ 2 Replies Last reply
    0
    • B Bryan Kelly

      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?

      Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Since a QLineEdit only holds some text, you should take a look into the QString documentation.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      0
      • B Bryan Kelly

        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?

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #3

        @Bryan-Kelly
        Don;t forget what I said in your other email, which is you would be better off using a QSpinBox/QDoubleSpinBox for entering numbers than a QLineEdit. It would do conversions between numbers and strings for you.

        B 1 Reply Last reply
        0
        • JonBJ JonB

          @Bryan-Kelly
          Don;t forget what I said in your other email, which is you would be better off using a QSpinBox/QDoubleSpinBox for entering numbers than a QLineEdit. It would do conversions between numbers and strings for you.

          B Offline
          B Offline
          Bryan Kelly
          wrote on last edited by Bryan Kelly
          #4

          @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?

          JonBJ 1 Reply Last reply
          0
          • B Bryan Kelly

            @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?

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #5

            @Bryan-Kelly
            You don't have any variable named le_q_a_input, simple as. If you created it in Designer, and that's its name, it's likely to be in ui, so ui->le_q_a_input. All widgets in Designer go into ui.

            B JonBJ 2 Replies Last reply
            0
            • JonBJ JonB

              @Bryan-Kelly
              You don't have any variable named le_q_a_input, simple as. If you created it in Designer, and that's its name, it's likely to be in ui, so ui->le_q_a_input. All widgets in Designer go into ui.

              B Offline
              B Offline
              Bryan Kelly
              wrote on last edited by Bryan Kelly
              #6

              @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.
              not_found.png
              I interpret that as a clear statement that the object by that name does indeed exist. So, how do I access it in code?

              JonBJ Pl45m4P 3 Replies Last reply
              0
              • B Bryan Kelly

                @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.
                not_found.png
                I interpret that as a clear statement that the object by that name does indeed exist. So, how do I access it in code?

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by JonB
                #7

                @Bryan-Kelly
                You write the same again. I said Designer puts all created widgets into ui. I suggested what you try. Did you read and do so?
                Yes it will be same issue no matter which widget type.

                B 1 Reply Last reply
                1
                • B Bryan Kelly

                  @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.
                  not_found.png
                  I interpret that as a clear statement that the object by that name does indeed exist. So, how do I access it in code?

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by JonB
                  #8

                  @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.

                  1 Reply Last reply
                  1
                  • JonBJ JonB

                    @Bryan-Kelly
                    You write the same again. I said Designer puts all created widgets into ui. I suggested what you try. Did you read and do so?
                    Yes it will be same issue no matter which widget type.

                    B Offline
                    B Offline
                    Bryan Kelly
                    wrote on last edited by Bryan Kelly
                    #9

                    @JonB said in Convert QLineEdit to float:

                    @Bryan-Kelly
                    You write the same again. I said Designer puts all created widgets into ui. 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.

                    1 Reply Last reply
                    0
                    • JonBJ JonB

                      @Bryan-Kelly
                      You don't have any variable named le_q_a_input, simple as. If you created it in Designer, and that's its name, it's likely to be in ui, so ui->le_q_a_input. All widgets in Designer go into ui.

                      JonBJ Offline
                      JonBJ Offline
                      JonB
                      wrote on last edited by
                      #10

                      @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.

                      B 1 Reply Last reply
                      0
                      • B Bryan Kelly

                        @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.
                        not_found.png
                        I interpret that as a clear statement that the object by that name does indeed exist. So, how do I access it in code?

                        Pl45m4P Offline
                        Pl45m4P Offline
                        Pl45m4
                        wrote on last edited by Pl45m4
                        #11

                        @Bryan-Kelly said in Convert QLineEdit to float:

                        Qt Creator states undeclared identifier.

                        Go to the private section of quadratic.h...
                        Most likely you have a variable called Ui::quadratic *ui there.
                        THIS is (the pointer to) your compiled user interface class (made by uic from quadratic.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 as ui object/variable in your quadratic.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


                        If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                        ~E. W. Dijkstra

                        1 Reply Last reply
                        1
                        • JonBJ JonB

                          @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.

                          B Offline
                          B Offline
                          Bryan Kelly
                          wrote on last edited by
                          #12

                          @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.

                          Pl45m4P 1 Reply Last reply
                          0
                          • B Bryan Kelly

                            @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.

                            Pl45m4P Offline
                            Pl45m4P Offline
                            Pl45m4
                            wrote on last edited by Pl45m4
                            #13

                            @Bryan-Kelly

                            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.


                            If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                            ~E. W. Dijkstra

                            1 Reply Last reply
                            2

                            • Login

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • Users
                            • Groups
                            • Search
                            • Get Qt Extensions
                            • Unsolved