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. [SOLVED]QLineEdit With Model
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]QLineEdit With Model

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 8.1k Views 1 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.
  • M Offline
    M Offline
    maherali
    wrote on last edited by
    #1

    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
    Thanks

    life is just lines of code

    1 Reply Last reply
    0
    • D Offline
      D Offline
      DenisKormalev
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • M Offline
        M Offline
        maherali
        wrote on last edited by
        #3

        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)

        Regards

        life is just lines of code

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0
          • M Offline
            M Offline
            maherali
            wrote on last edited by
            #5

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

            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.

            Regards

            life is just lines of code

            1 Reply Last reply
            0
            • M Offline
              M Offline
              maherali
              wrote on last edited by
              #6

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

              life is just lines of code

              1 Reply Last reply
              0

              • Login

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