Nominate our 2022 Qt Champions!

[SOLVED]QLineEdit With Model

  • Hi all
    I need to know if there is a way to bind both QLineEdit to a model that is already assigned to a QTableView.
    this was easy in C# using databinding.

    Any ideas will be appreciated

  • Hm, can you elaborate what you mean by bind QLIneEdit (one value) to model (a lot of values)?

  • Yes the IDEA is just as POC (Proof of concept)
    QTableView and QLineEdit in the MainWindow
    There is a model that is derived from QAbstractTableModel, where I have a custom model that will be the data source (in .NET terminology) for the QTableView
    When I click on one row, there should appear a specific column value in the LineEdit (lets say the first one which represent the first name),by changing the row the value should change to reflect the current row.

    When changing the value of LineEdit it should also instantaneously be changed in the QTableView because they have the same source.
    This was easy to do with C# by setting the datasource field name (I miss those days)


  • I think you are looking for [[Doc:QDataWidgetMapper]].

  • Thanks Andre, it's really what I was looking for I've did the following and it worked
    @ ui->setupUi(this);
    mymodel=new MyModel();
    mapper=new QDataWidgetMapper();

    There are problem I'll try to figure out, when changing the selection on QTableView the LineEdit is not updated.
    When changing the text in the lineEdit the text in the view doesn't change unless I leave the cell.


  • I think it needs a lot of work, anyway thank you Andre, that's what I was looking for.

Log in to reply