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. QLineEdit::editingFinished() [signal] is emitted twice
QtWS25 Last Chance

QLineEdit::editingFinished() [signal] is emitted twice

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 13.5k Views
  • 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.
  • S Offline
    S Offline
    SangVn
    wrote on 17 Mar 2014, 17:53 last edited by
    #1

    Hi all,

    I have a problem with QLineEdit. The signal "editingFinished()" is emitted twice when "Enter key" is pressed.

    My Slot:
    void Dialog::on_LineEdit_editingFinished()
    {
    if(ui->LineEdit->text().toDouble()<1000)
    QMessageBox::information(this,"Information","Incorrect value ");
    }

    QMessageBox is called twice when Enter key is pressed ( but it is called one when the line edit loses focus).

    How to fix this problem?
    Please advise.

    1 Reply Last reply
    0
    • F Offline
      F Offline
      frankiefrank
      wrote on 17 Mar 2014, 18:06 last edited by
      #2

      Looks like you hit a Qt bug.

      See here:
      https://bugreports.qt-project.org/browse/QTBUG-40

      This has been around for a long time and I'm not sure what's the policy on reopening old bugs, maybe some "inside" folks can advise on that.

      In my code to work around the issue I added a check to see if the text has changed since the last triggering.

      "Roads? Where we're going, we don't need roads."

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 17 Mar 2014, 21:33 last edited by
        #3

        Hi and welcome to devnet,

        As a quick workaround you can use:

        @
        if(lineEdit->text().toDouble()<1000) {
        lineEdit->blockSignals(true);
        QMessageBox::information(this, "Information", "Incorrect value");
        lineEdit->blockSignals(false);
        }
        @

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SangVn
          wrote on 18 Mar 2014, 08:25 last edited by
          #4

          Thank you, frankiefrank.
          Thank you, SGaist. It works great!

          @
          void Dialog::on_LineEdit_editingFinished()
          {
          if(ui->LineEdit->text().toDouble()<1000)
          {
          ui->LineEdit->blockSignals(true);
          QMessageBox::information(this,“Information”,“Incorrect value “);
          ui->LineEdit->blockSignals(false);
          }
          }
          @

          1 Reply Last reply
          0
          • F Offline
            F Offline
            frankiefrank
            wrote on 18 Mar 2014, 10:51 last edited by
            #5

            Please edit your post to include [SOLVED] :)

            "Roads? Where we're going, we don't need roads."

            1 Reply Last reply
            0

            5/5

            18 Mar 2014, 10:51

            • Login

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