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. IP Editor popuppad Delete not clearing LineEdit
Servers for Qt installer are currently down

IP Editor popuppad Delete not clearing LineEdit

Scheduled Pinned Locked Moved Solved General and Desktop
ip editorplugindeletekeypresseventbackspace
13 Posts 3 Posters 4.3k Views 3 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.
  • S Sh1gs
    6 Jun 2017, 18:21

    Hi everyone,

    I apologize for making the bajillion topic posts about my IP Editor. Every time I think I'm done with it, something else needs to be added/modified. Anyhoo! I made an IP Editor plugin that uses 4 lineedits, similar to this:

    ___.___.___.___
    

    A numberpad intended for touchscreen use, pops up when the LineEdits have focus. For each button on the numberpad, I am sending a QEvent::KeyPress. When implementing the "Delete" key, I made sure it was set to autorepeat. For the Delete key, I am sending a KeyEvent that Backspace was pressed.

    The problem I am having is that, if the complete IP Address is entered, for example 123.123.123.123, and the user presses and holds down the Delete key, it deletes 123 then moves to the previous LineEdit, but stops. I have to press Delete again in order to delete the next three numbers, and so on, until the IP Editor is empty again. When I use the Backspace key on the keyboard, it works fine. Does aynone have an idea of what's going on?

    Thanks

    K Offline
    K Offline
    koahnig
    wrote on 6 Jun 2017, 18:45 last edited by
    #2

    @Sh1gs

    You are trying to get people to crystal ball reading. You need to post a code snippet showing the problem.

    Vote the answer(s) that helped you to solve your issue(s)

    1 Reply Last reply
    5
    • S Offline
      S Offline
      Sh1gs
      wrote on 8 Jun 2017, 15:09 last edited by
      #3

      My lineedits are receiving data in a function called "receiveData". In this function, for the delete key, I have the following:

      QKeyevent *event = new QKeyEvent(QEvent::keyPress, Qt::Key_Backspace, Qt::NoModifier, text, true);
      QApplication::sendEvent(this, event);
      QApplication::postEvent(curEdit, event);
      curEdit->installEventFilter(this);
      

      So when delete is pressed, it goes to my event filter which has:

      case Qt::Key_Backspace:
      if(input->text.isEmpty)
        movPrevLE(i);
      break;
      

      and then finally in movPrevLE, I have:

      if(i!=0)
        leList[i-1]->setFocus();
        leList[i-1]->setCursorPos(leList[i-1]->text.size());
      

      It works with the Backspace on the keyboard, but when I press and hold my delete key, it only deletes the current line edit text, moves to the previous line edit, and then stops. I'm assuming it's a signal/event issue that it needs to keep being triggered, but I'm not sure how to go about it.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Sh1gs
        wrote on 15 Jun 2017, 15:33 last edited by
        #4

        I have seen these two Bug reports and am wondering if that is why I'm having difficult. Could someone shed some light on this?

        QTBUG-19060

        QTBUG-20444

        Thanks.

        K 1 Reply Last reply 15 Jun 2017, 15:46
        0
        • S Sh1gs
          15 Jun 2017, 15:33

          I have seen these two Bug reports and am wondering if that is why I'm having difficult. Could someone shed some light on this?

          QTBUG-19060

          QTBUG-20444

          Thanks.

          K Offline
          K Offline
          koahnig
          wrote on 15 Jun 2017, 15:46 last edited by koahnig
          #5

          @Sh1gs said in IP Editor popuppad Delete not clearing LineEdit:

          I have seen these two Bug reports and am wondering if that is why I'm having difficult. Could someone shed some light on this?

          QTBUG-19060

          QTBUG-20444

          Thanks.

          Both bug reports are referring to 4.7.4 and are closed. One is done and the other was a duplicate. All this is 6 years old.
          In case you are still using Qt4 this would be a good information to supply as well. Probably more than 95% of users here are definitely on Qt 5. As noted above crystal ball reading is not a common gift for those people trying to help.

          Certainly there is always a chance that bugs are slipping back. However, chances are typically in the low percentage.

          Vote the answer(s) that helped you to solve your issue(s)

          S 1 Reply Last reply 15 Jun 2017, 18:19
          0
          • K koahnig
            15 Jun 2017, 15:46

            @Sh1gs said in IP Editor popuppad Delete not clearing LineEdit:

            I have seen these two Bug reports and am wondering if that is why I'm having difficult. Could someone shed some light on this?

            QTBUG-19060

            QTBUG-20444

            Thanks.

            Both bug reports are referring to 4.7.4 and are closed. One is done and the other was a duplicate. All this is 6 years old.
            In case you are still using Qt4 this would be a good information to supply as well. Probably more than 95% of users here are definitely on Qt 5. As noted above crystal ball reading is not a common gift for those people trying to help.

            Certainly there is always a chance that bugs are slipping back. However, chances are typically in the low percentage.

            S Offline
            S Offline
            Sh1gs
            wrote on 15 Jun 2017, 18:19 last edited by
            #6

            @koahnig

            The snide comment is unnecessary. This is why people get frustrated when posting on forums. As I've stated above, I provided as much code as I can, unfortunately I cannot provide everything because of the nature of my job and the hoops I have to jump through to post what I have already.

            I simply came on here to ask for help regarding a KeyPressEvent for a delete key to act as the Backspace key on the keyboard, and why it only deletes the the current LineEdit, moves to the previous LineEdit, and stops.

            M 1 Reply Last reply 15 Jun 2017, 19:36
            0
            • S Sh1gs
              15 Jun 2017, 18:19

              @koahnig

              The snide comment is unnecessary. This is why people get frustrated when posting on forums. As I've stated above, I provided as much code as I can, unfortunately I cannot provide everything because of the nature of my job and the hoops I have to jump through to post what I have already.

              I simply came on here to ask for help regarding a KeyPressEvent for a delete key to act as the Backspace key on the keyboard, and why it only deletes the the current LineEdit, moves to the previous LineEdit, and stops.

              M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 15 Jun 2017, 19:36 last edited by
              #7

              @Sh1gs
              Hi
              When you say delete key , you refer to Qt::Key_Backspace: ?

              So as i understand it, this goes to prev edit if its empty
              case Qt::Key_Backspace:
              if(input->text.isEmpty)
              movPrevLE(i);
              break;

              So i wonder why it can one back and then stop. Did you try with debugger and
              see if movPrevLE(i); does as expected? and than i is also expected index.

              Since it works for first two, i wonder if it seems it as not empty.

              You can insert qDebug statements to see what differs when in second edit and
              if the delete key is still being sent.

              S 1 Reply Last reply 15 Jun 2017, 19:50
              0
              • M mrjj
                15 Jun 2017, 19:36

                @Sh1gs
                Hi
                When you say delete key , you refer to Qt::Key_Backspace: ?

                So as i understand it, this goes to prev edit if its empty
                case Qt::Key_Backspace:
                if(input->text.isEmpty)
                movPrevLE(i);
                break;

                So i wonder why it can one back and then stop. Did you try with debugger and
                see if movPrevLE(i); does as expected? and than i is also expected index.

                Since it works for first two, i wonder if it seems it as not empty.

                You can insert qDebug statements to see what differs when in second edit and
                if the delete key is still being sent.

                S Offline
                S Offline
                Sh1gs
                wrote on 15 Jun 2017, 19:50 last edited by
                #8

                @mrjj

                I apologize for not being more clear. I have a numberpad that pops up on screen whenever one of the LineEdits has focus, essentially my version of a "virtual keyboard". I have made sure that all of the PushButtons don't have focus. I have a "Delete" PushButton within that numberpad, that I want to act as the "Backspace" key on the keyboard. So when "Delete" is clicked, I have:

                QKeyevent *event = new QKeyEvent(QEvent::keyPress, Qt::Key_Backspace, Qt::NoModifier, text, true);
                QApplication::sendEvent(this, event);
                QApplication::postEvent(curEdit, event);
                QKeyevent *rE = new QKeyEvent(QEvent::keyRelease, Qt::Key_Backspace, Qt::NoModifier, text, true);
                QApplication::sendEvent(this, rE);
                QApplication::postEvent(curEdit, rE);
                curEdit->installEventFilter(this);
                

                Then when it goes to the eventFilter, it has as you wrote:

                case Qt::Key_Backspace:
                if(input->text.isempty())
                movPrevLE(i);
                break;
                

                It works with the backspace key on the keyboard, but for the life of me, I cannot figure out why the Delete PushButton I created doesn't act the same way. The Delete button moves fine and deletes if I keep pressing it. But if I press and hold, it only deletes the current LineEdit it is in, moves to the previous LineEdit, and then doesn't delete until it's pressed again.

                I have added qDebug() statements to see if the Press and Release events are occuring, and they are. I have also seen that it is indeed moving to the previous LineEdit.

                M 1 Reply Last reply 15 Jun 2017, 20:10
                0
                • S Sh1gs
                  15 Jun 2017, 19:50

                  @mrjj

                  I apologize for not being more clear. I have a numberpad that pops up on screen whenever one of the LineEdits has focus, essentially my version of a "virtual keyboard". I have made sure that all of the PushButtons don't have focus. I have a "Delete" PushButton within that numberpad, that I want to act as the "Backspace" key on the keyboard. So when "Delete" is clicked, I have:

                  QKeyevent *event = new QKeyEvent(QEvent::keyPress, Qt::Key_Backspace, Qt::NoModifier, text, true);
                  QApplication::sendEvent(this, event);
                  QApplication::postEvent(curEdit, event);
                  QKeyevent *rE = new QKeyEvent(QEvent::keyRelease, Qt::Key_Backspace, Qt::NoModifier, text, true);
                  QApplication::sendEvent(this, rE);
                  QApplication::postEvent(curEdit, rE);
                  curEdit->installEventFilter(this);
                  

                  Then when it goes to the eventFilter, it has as you wrote:

                  case Qt::Key_Backspace:
                  if(input->text.isempty())
                  movPrevLE(i);
                  break;
                  

                  It works with the backspace key on the keyboard, but for the life of me, I cannot figure out why the Delete PushButton I created doesn't act the same way. The Delete button moves fine and deletes if I keep pressing it. But if I press and hold, it only deletes the current LineEdit it is in, moves to the previous LineEdit, and then doesn't delete until it's pressed again.

                  I have added qDebug() statements to see if the Press and Release events are occuring, and they are. I have also seen that it is indeed moving to the previous LineEdit.

                  M Offline
                  M Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on 15 Jun 2017, 20:10 last edited by
                  #9

                  @Sh1gs
                  Hi
                  it might be related to how auto repeat is working.
                  I assume you have
                  button->setAutoRepeat(true);
                  and tweaked setAutoRepeatInterval and setAutoRepeatDelay to your like.

                  If you (for test) use a timer and call the same code, does it then work?

                  S 2 Replies Last reply 16 Jun 2017, 14:09
                  0
                  • M mrjj
                    15 Jun 2017, 20:10

                    @Sh1gs
                    Hi
                    it might be related to how auto repeat is working.
                    I assume you have
                    button->setAutoRepeat(true);
                    and tweaked setAutoRepeatInterval and setAutoRepeatDelay to your like.

                    If you (for test) use a timer and call the same code, does it then work?

                    S Offline
                    S Offline
                    Sh1gs
                    wrote on 16 Jun 2017, 14:09 last edited by
                    #10

                    @mrjj

                    Yes, I have delete->setAutoRepeat(true); as well as the parameter AutoRep in my keyPress is set to True. I did not change the autorepeatinterval or delay.

                    I am not as familiar with QTimer, so how would I go about implementing that? Would it be something like...

                    QTimer *timer = new QTimer(this);
                    connect(timer, SIGNAL(timeout()), this, SLOT(what slot to use?));
                    timer->start(some amount of time);
                    

                    Where would this section of code go?

                    1 Reply Last reply
                    0
                    • M mrjj
                      15 Jun 2017, 20:10

                      @Sh1gs
                      Hi
                      it might be related to how auto repeat is working.
                      I assume you have
                      button->setAutoRepeat(true);
                      and tweaked setAutoRepeatInterval and setAutoRepeatDelay to your like.

                      If you (for test) use a timer and call the same code, does it then work?

                      S Offline
                      S Offline
                      Sh1gs
                      wrote on 16 Jun 2017, 15:09 last edited by
                      #11

                      @mrjj

                      Ok, this may not be correct, but I put the following within my eventFilter under Qt::Key_Backspace:

                      QTimer *timer = new QTimer(this);
                      connect(timer, SIGNAL(timeout(), this, SLOT(update()));
                      timer->start(100);
                      

                      Then in my update() slot, I am emitting that "delete" was pressed.

                      Doing this, deletes all of the LineEdit texts. Now I am having an issue that the signal keeps being sent as if the "Delete" key is being pressed/released for eternity, then it crashes. I've tried disconnecting the timer, and I've tried timer->stop() but that doesn't seem to fix the issue either. At least I'm getting closer :)

                      M 1 Reply Last reply 16 Jun 2017, 16:02
                      0
                      • S Sh1gs
                        16 Jun 2017, 15:09

                        @mrjj

                        Ok, this may not be correct, but I put the following within my eventFilter under Qt::Key_Backspace:

                        QTimer *timer = new QTimer(this);
                        connect(timer, SIGNAL(timeout(), this, SLOT(update()));
                        timer->start(100);
                        

                        Then in my update() slot, I am emitting that "delete" was pressed.

                        Doing this, deletes all of the LineEdit texts. Now I am having an issue that the signal keeps being sent as if the "Delete" key is being pressed/released for eternity, then it crashes. I've tried disconnecting the timer, and I've tried timer->stop() but that doesn't seem to fix the issue either. At least I'm getting closer :)

                        M Offline
                        M Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on 16 Jun 2017, 16:02 last edited by
                        #12

                        @Sh1gs
                        Super.
                        It was not meant as a solution.
                        I just wondered if the function would indeed work if something other than a repeating button was used.

                        So it's fair to say the logic works (it will go through all 4) and it will clean all edits
                        and it does send pressed/released as expected.

                        Unless i missed something, it seems its the autorepeat feature that does something unexpected.

                        Also i wonder other thing.

                        in receiveData
                        you call curEdit->installEventFilter(this);
                        and as far as i understand it means it will be called multiple times.
                        Normally you call it once, when you create the curEdit.
                        Not sure if it will only be added once and others calls are just ignored. ( there can be mutiple)
                        Would it be possible to move this line to where you create curEdit so its for sure only installed once?

                        I think i understand the design now and i see no reason to differently with a button but im sure we can find it.

                        S 1 Reply Last reply 16 Jun 2017, 19:25
                        0
                        • M mrjj
                          16 Jun 2017, 16:02

                          @Sh1gs
                          Super.
                          It was not meant as a solution.
                          I just wondered if the function would indeed work if something other than a repeating button was used.

                          So it's fair to say the logic works (it will go through all 4) and it will clean all edits
                          and it does send pressed/released as expected.

                          Unless i missed something, it seems its the autorepeat feature that does something unexpected.

                          Also i wonder other thing.

                          in receiveData
                          you call curEdit->installEventFilter(this);
                          and as far as i understand it means it will be called multiple times.
                          Normally you call it once, when you create the curEdit.
                          Not sure if it will only be added once and others calls are just ignored. ( there can be mutiple)
                          Would it be possible to move this line to where you create curEdit so its for sure only installed once?

                          I think i understand the design now and i see no reason to differently with a button but im sure we can find it.

                          S Offline
                          S Offline
                          Sh1gs
                          wrote on 16 Jun 2017, 19:25 last edited by
                          #13

                          @mrjj

                          I've changed it to check if it's in the first edit, to stop the timer so it'd look like

                          123.___.___.___
                          

                          And then the user will have to manually hit "Delete" repeatedly to delete the characters. This way, the program doesn't crash. It's not exactly elegant, but it's close enough to the requirements I was given.

                          I have also changed that curEdit->installEventFilter(this) is only called once.

                          Thank you very much for your help, I will go ahead and mark this as solved.

                          1 Reply Last reply
                          0

                          • Login

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