Qt Forum

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

    Unsolved Adjusting QLineEdit undo signal

    General and Desktop
    5
    9
    973
    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.
    • D
      Dariusz last edited by

      Hey

      I'm trying to emit a signal once undo or redo slots are being used by qt. How can I do it? Initially I started with subclassing the void undo()/redo but they are not virtual so my code had no effect : -(

      TIA

      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        Hi,

        Can you explain why do you need it for ?

        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 Reply Quote 0
        • D
          Dariusz last edited by

          I don't want to change the native qt/ undo/redo for its qline edits but I do need to cast a signal when a value has been undone in order to notify some processes to recalculate their functions. Else the text just gets undone but nothing changes that needs to.

          Regards
          Dariusz

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

            @Dariusz
            QLineEdit::undo() is a slot, not a signal. There is no signal issued for undo. As you say, you cannot sub-class it because it's not virtual (why not, I'm not sure).

            The most obvious simple solution is to check to see whether undo/redo do indeed cause QLineEdit::textChanged (not textEdited) signal to be emitted. (I would suspect they do, as undo/redo is a change of text, but I could be wrong.) Then you do your stuff in that handler slot. You won't be able to recognise an undo/redo versus any other edit, but then your code should not need that, as undo/redoes are simply the same thing as the corresponding edit anyway.

            Pablo J. Rogina 1 Reply Last reply Reply Quote 2
            • Pablo J. Rogina
              Pablo J. Rogina @JonB last edited by

              @JonB said in Adjusting QLineEdit undo signal:

              QLineEdit::undo() is a slot

              right, so being a slot he'll be calling it somehow. I guess that just after calling undo() a custom signal can be emitted. Pseudo-code:

              MyClass {
              ...
              myLineEdit = QLineEdit()
              ...
              signal:
              undoFired()
              ...
              MyClass::handleUndo() {
                  myLineEdit.undo();
                  emit undoFired();
              }
              
              SomeOtherClass {
              
              myClass = new MyClass();
              public slots:
                  updateBecauseUndo();
              ...
              connect(myClass, SIGNAL(undoFired()), this, SLOT(updateBecauseUndo());
              ...
              }
              
              SomeOtherClass::updateBecauseUndo() {
                  // do calculations because QLineEdit::undo() was fired somewhere
              }
              

              Upvote the answer(s) that helped you solve the issue
              Use "Topic Tools" button to mark your post as Solved
              Add screenshots via postimage.org
              Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

              JonB 1 Reply Last reply Reply Quote 0
              • JonB
                JonB @Pablo J. Rogina last edited by

                @Pablo-J.-Rogina
                Yes, but this only works because you have created your own class to wrap a QLineEdit, and so can do what you like.

                Let's assume the OP (or whoever) already has an app which has hundreds of native QLineEdits in it, and author used them directly, not via proprietary sub-class.

                Let's assume that undo gets fired after user types some characters and then presses Ctrl+Z --- which I presume makes Qt fire the undo, right?

                He wants to know about that "undo". So now how?

                Pablo J. Rogina 1 Reply Last reply Reply Quote 0
                • Pablo J. Rogina
                  Pablo J. Rogina @JonB last edited by

                  @JonB said in Adjusting QLineEdit undo signal:

                  an app which has hundreds of native QLineEdits in it, and author used them directly, not via proprietary sub-class.

                  Whatever you have, a QLineEdit object must be contained into any other class. Simplest example I imagine is a MainWindow without any layout having the QLineEdit, so you indeed always have a "custom" class where you can add whatever methods you need, that's not a problem.

                  Let's assume that undo gets fired after user types some characters and then presses Ctrl+Z --- which I presume makes Qt fire the undo, right?

                  Your assumption is not valid, QLineEdit::undo is an SLOT so it won't get fired...

                  Upvote the answer(s) that helped you solve the issue
                  Use "Topic Tools" button to mark your post as Solved
                  Add screenshots via postimage.org
                  Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

                  JonB 1 Reply Last reply Reply Quote 1
                  • JonB
                    JonB @Pablo J. Rogina last edited by

                    @Pablo-J.-Rogina said in Adjusting QLineEdit undo signal:

                    Let's assume that undo gets fired after user types some characters and then presses Ctrl+Z --- which I presume makes Qt fire the undo, right?

                    Your assumption is not valid, QLineEdit::undo is an SLOT so it won't get fired...

                    I know it's a slot. I meant, my understanding is, user clicks Ctrl+Z, Qt framework fires signal UNDO, QLineEdit's undo slot gets notified from signal. Maybe that's not how it works, dunno...

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

                      Hi
                      QLineEdit::textChanged is triggered by undo.
                      Btw i also thought undo() / redo() was signals but turns out they are for external activation.

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