Synchronize 2 QlineEdit



  • Dear all, I have a window with some QlineEdit fields and I would like to synchronize 2 of them so that when I change the text in one, also the other is updated. For the moment I have solved the problem creating a slot textChanged () for each of the 2 fields and inside putting a setText () to the other field. Is there some other implementation that gives the same result but without having to modify both slots?


  • Qt Champions 2016

    Hi
    You can directly connect
    Edit1
    QLineEdit::textChanged(const QString &text)
    to Edit2
    void setText(const QString &)
    and reverse
    Then typing in one will type same in other.



  • Yes, this is exactly what I am doing. I just wanted to know is there is a smarter way to synchronise two or more fields.


  • Qt Champions 2016

    Ok, i read it like you implemented a slot to set text and not directly used
    2 connects. (with no slot implementation). that is the most compact way.

    There is also
    http://doc.qt.io/qt-5/qdatawidgetmapper.html#details
    Which makes it easy to share a model with multiple widgets.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.