Adjusting QLineEdit undo signal
-
Hi,
Can you explain why do you need it for ?
-
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 -
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@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 notvirtual(why not, I'm not sure).The most obvious simple solution is to check to see whether undo/redo do indeed cause
QLineEdit::textChanged(nottextEdited) 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. -
@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 notvirtual(why not, I'm not sure).The most obvious simple solution is to check to see whether undo/redo do indeed cause
QLineEdit::textChanged(nottextEdited) 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.@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 } -
@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 }@Pablo-J.-Rogina
Yes, but this only works because you have created your own class to wrap aQLineEdit, 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
undogets fired after user types some characters and then presses Ctrl+Z --- which I presume makes Qt fire theundo, right?He wants to know about that "undo". So now how?
-
@Pablo-J.-Rogina
Yes, but this only works because you have created your own class to wrap aQLineEdit, 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
undogets fired after user types some characters and then presses Ctrl+Z --- which I presume makes Qt fire theundo, right?He wants to know about that "undo". So now how?
@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...
-
@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...
@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...
-
Hi
QLineEdit::textChanged is triggered by undo.
Btw i also thought undo() / redo() was signals but turns out they are for external activation.