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] QSqlTableModel::dataChanged() is never emitted, I think...
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] QSqlTableModel::dataChanged() is never emitted, I think...

Scheduled Pinned Locked Moved General and Desktop
7 Posts 2 Posters 3.6k 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.
  • I Offline
    I Offline
    i92guboj
    wrote on last edited by
    #1

    I have a QSqlTableModel tied to a QTableView, I am trying to do some stuff in adjacent cells when a given cell is altered, but dataChanged() doesn't seem to ever be emitted by the model and the relevant SLOT is, hence, never called.

    [code]
    connect(ui->tableView_cascosYAccesorios->model(), SIGNAL(dataChanged(QModelIndex,QModelIndex)),
    this, SLOT(cascos_y_accesorios_dataChanged(QModelIndex,QModelIndex)));
    ...
    void kooker::cascos_y_accesorios_dataChanged(QModelIndex, QModelIndex)
    {
    qDebug() << Q_FUNC_INFO << "something changed in this table!!";
    }
    [/code]

    I have set the model this way, in case it matters...

    [code]
    models.cases_and_accesories->setEditStrategy(QSqlTableModel::OnFieldChange);
    [/code]

    Do I have to do something else so that the QSqlTableModel is able to emit this SIGNAL?

    Thank you :)

    1 Reply Last reply
    0
    • JeroentjehomeJ Offline
      JeroentjehomeJ Offline
      Jeroentjehome
      wrote on last edited by
      #2

      hmm, the emit of dataChanged you should do yourself. The View doesn't control the data, you do.
      When you change data, emit the signal.

      Greetz, Jeroen

      1 Reply Last reply
      0
      • I Offline
        I Offline
        i92guboj
        wrote on last edited by
        #3

        [quote author="Jeroentje@home" date="1376649294"]hmm, the emit of dataChanged you should do yourself. The View doesn't control the data, you do.
        When you change data, emit the signal.
        [/quote]

        But I am not subclassing. I use a standard QSqlTableModel (and we are talking about a "model", not a "view"). As far as I know, the model should be responsible for emitting the signal and I can't emit it unless I am subclassing it.

        Anyway, I have found a few other people having the same problem in Google. I "solved" it by using the "OnManualSubmit" policy. Now it works, and the model emits the signal as it should.

        I am not knowledgeable enough to understand why they decided to emit this with one policy but not the other, though...

        Thank you for your response :)

        1 Reply Last reply
        0
        • JeroentjehomeJ Offline
          JeroentjehomeJ Offline
          Jeroentjehome
          wrote on last edited by
          #4

          Ah,
          Sorry, misunderstood what you posted.
          Hmm, never used the sql model before, so not real sure what goes on in the background. When I read the docs it has to do in the way the model controls the data from and to the database. The OnFieldChanged should emit the dataChanged signal when an "older" row is changed IYAM. Only for new rows the OnRowChanged will emit the signal (to avoid writing incomplete rows into the database).
          No idea what the difference might cause. There is always an option of downloading the source code and have a look. ;-)
          That is usually very informative.

          Greetz, Jeroen

          1 Reply Last reply
          0
          • I Offline
            I Offline
            i92guboj
            wrote on last edited by
            #5

            I have the source code for all my OS at hand, since I use Gentoo Linux, qt is no exception to that rule ;) I will eventually look at what those classes do, but right now I don't think I have the insight I'd need to do so.

            On a second thought, OnManualSubmit will do ok for my purposes. Curiosity can wait :)

            Thanks!!

            1 Reply Last reply
            0
            • JeroentjehomeJ Offline
              JeroentjehomeJ Offline
              Jeroentjehome
              wrote on last edited by
              #6

              oke,
              Post [SOLVED] if front of your first post if you think no more answers are needed.
              Happy coding!!

              Greetz, Jeroen

              1 Reply Last reply
              0
              • I Offline
                I Offline
                i92guboj
                wrote on last edited by
                #7

                Thank you for the reminder. I am new to these forums :)

                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