Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved Assigning LineEdit input value to a variable

    General and Desktop
    3
    6
    817
    Loading More Posts
    • 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.
    • F
      FamaFrench last edited by

      Okay, here's what I'm attempting to accomplish.

      1.Have the user enter a value into a QLineEdit object (Float only)

      2.Save that input to a variable

      My problem:

               1.is editingFinished(); an appropriate function for saving input in LineEdit box?
      

      So far, my code is:

      void MainWindow::on_lineEdit_4_editingFinished()
      
      { int CouponRate;
      
      QString Coup = ui->CPR->text();
      
      }
      

      (CPR is the object name of the lineedit)

      1. As you can tell, I am quite lost. All help will be greatly appreciated.
      JonB 1 Reply Last reply Reply Quote 0
      • mrjj
        mrjj Lifetime Qt Champion last edited by mrjj

        Hi and welcome to the forums

        Well the editingFinished, is emitted when the user press return/enter or simply leave the LineEdit so if that fit how they should use it, its
        ok place to do it. ( most use cases fit this use)

        void MainWindow::on_lineEdit_4_editingFinished() {
        QString Coup = ui->CPR->text();
        float CouponRate = Coup.ToFloat(); // get it as float
        }
        

        Note that are other ToXX for other types.

        Also, note that ToXXX can take a bool to tell if the convert went ok or not.
        That can be used to validate user input;

        1 Reply Last reply Reply Quote 0
        • JonB
          JonB @FamaFrench last edited by JonB

          @FamaFrench said in Assigning LineEdit input value to a variable:

          Have the user enter a value into a QLineEdit object (Float only)

          What does "Float only" mean? If you mean a floating point value (12.34) you would be best using a QDoubleSpinBox widget, as that will limit.validate input and return the value as a double instead of you doing conversion work.

          editingFinished() is a perfectly good signal to use to detect end of editing and ready to save. It is available on QDoubleSpinBox just as much as on QLineEdit.

          mrjj 1 Reply Last reply Reply Quote 2
          • mrjj
            mrjj Lifetime Qt Champion @JonB last edited by

            @JonB
            Oh I miss the float thing :)
            Then converting to an int wont make him happy

            JonB 1 Reply Last reply Reply Quote 0
            • JonB
              JonB @mrjj last edited by

              @mrjj
              Wait to see, it may not mean that at all! It might be to do with a "floating window", I don't know :)

              mrjj 1 Reply Last reply Reply Quote 0
              • mrjj
                mrjj Lifetime Qt Champion @JonB last edited by

                @JonB
                Hi
                Also if that float is money, he might want to look at QLocale
                to get the separators right.

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post