PDA

View Full Version : How to modify text sent from one text widget to another?



tom.hedden
11th May 2014, 03:03
I have been working on tutorials showing how to create applications that send text typed in one text widget to another text widget using signals and slots. I want to do that, but I want to be able to transform the text as it is sent, so that the text that appears in the target is different from what is typed in the source. For example, if I type text in one widget, I might want to transform the typed text using a Caesar cipher:
Now is the time ...
Klt fp qeb qfjb ...
(Each letter is shifted three positions to the left in the order of the alphabet.).
I want to be able to write a function that will transform the input text and add it to the code produced by, for example, Qt Creator.
However, when I open the files it creates, it appears that all the work is being done behind the scenes by supplied code.
I have no idea whether it is possible to modify it or how to do so.
Can anyone shed any light on this? By that I mean, what file to modify or add, where to put it, etc.
Thanks in advance for any suggestions.
Tom

ChrisW67
11th May 2014, 08:29
Let us assume you have connected QLineEdit::textChanged() (signal) to QLineEdit::setText() (slot) to get an instant direct transfer. To change the text you need to connect the signal to a slot that does the transformation and then calls setText() (directly or indirectly) with the changed value. You can make it a custom slot in the sender class that emits a custom signal with the transformed value, or you could make it a custom slot in the receiving class that simply calls setText() after transforming the input. Where you put the transforming slot is a matter of design/choice.