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. How to deal with dataChanged from TableView Model signal
Forum Updated to NodeBB v4.3 + New Features

How to deal with dataChanged from TableView Model signal

Scheduled Pinned Locked Moved Solved General and Desktop
tableviewmodeldatachangedsignal
3 Posts 2 Posters 10.0k Views 2 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.
  • D Offline
    D Offline
    Dashie
    wrote on last edited by
    #1

    I have a TableView with a Model, i can double-click to edit cells and i need to get the edit stuff to update in the BDD.

    I've got the following that is triggered after enter:

    connect(ui->tableViewQso->model(),
            SIGNAL(dataChanged(QModelIndex,QModelIndex)), this,
            SLOT(onUpdateQso(const QModelIndex&, const QModelIndex&)));
    ...
    void qthLogMW::onUpdateQso(const QModelIndex &topLeft, const QModelIndex &bottomRight) {
         statusLabel->setText(tr("Asked for update"));
    }
    

    How i could get edit stuff ? I can't found what to do with topLeft & botRight.

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      You are not supposed to connect to dataChanged from outside. I mean you of course can and in some cases that's useful, but that is not how model/view in Qt works.
      When the edit finishes a setData of the model is called. In there you should set the data in whatever storage for it you have and if it succeeded emit dataChanged and return true.
      In the simplest form dataChanged will have topLeft and bottomRight values pointing to the same index - the one that was just edited and passed to setData.
      If there is some data dependency going on, where a change of one value causes others to change too, you can emit dataChanged with a "rectangular" region indicated by topLeft and bottomRight that contains the changed values.
      In response to dataChanged the view will invalidate the indicated region and query the model with its data() member for the changed values.

      D 1 Reply Last reply
      0
      • Chris KawaC Chris Kawa

        You are not supposed to connect to dataChanged from outside. I mean you of course can and in some cases that's useful, but that is not how model/view in Qt works.
        When the edit finishes a setData of the model is called. In there you should set the data in whatever storage for it you have and if it succeeded emit dataChanged and return true.
        In the simplest form dataChanged will have topLeft and bottomRight values pointing to the same index - the one that was just edited and passed to setData.
        If there is some data dependency going on, where a change of one value causes others to change too, you can emit dataChanged with a "rectangular" region indicated by topLeft and bottomRight that contains the changed values.
        In response to dataChanged the view will invalidate the indicated region and query the model with its data() member for the changed values.

        D Offline
        D Offline
        Dashie
        wrote on last edited by
        #3

        @Chris-Kawa thanks, i now see the thing.
        I've found example http://doc.qt.io/qt-5/modelview.html#2-5-the-minimal-editing-example but it use QAbstractTableModel and i'm using a QSqlRelationalTableModel instead of QSqlTableModel.

        Will it still works for relations ? I can't found an Abstract for RelationalTableModel.

        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