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. Adjusting QLineEdit undo signal
Qt 6.11 is out! See what's new in the release blog

Adjusting QLineEdit undo signal

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 5 Posters 1.9k 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.
  • D Offline
    D Offline
    Dariusz
    wrote on last edited by
    #1

    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
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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
      0
      • D Offline
        D Offline
        Dariusz
        wrote on last edited by
        #3

        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

        JonBJ 1 Reply Last reply
        0
        • D Dariusz

          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

          JonBJ Online
          JonBJ Online
          JonB
          wrote on last edited by JonB
          #4

          @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. RoginaP 1 Reply Last reply
          2
          • JonBJ 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. RoginaP Offline
            Pablo J. RoginaP Offline
            Pablo J. Rogina
            wrote on last edited by
            #5

            @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

            JonBJ 1 Reply Last reply
            0
            • Pablo J. RoginaP Pablo J. Rogina

              @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
              }
              
              JonBJ Online
              JonBJ Online
              JonB
              wrote on last edited by
              #6

              @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. RoginaP 1 Reply Last reply
              0
              • JonBJ JonB

                @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. RoginaP Offline
                Pablo J. RoginaP Offline
                Pablo J. Rogina
                wrote on last edited by
                #7

                @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

                JonBJ 1 Reply Last reply
                1
                • Pablo J. RoginaP Pablo J. Rogina

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

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

                  @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
                  0
                  • mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by mrjj
                    #9

                    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
                    1

                    • Login

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