Important: Please read the Qt Code of Conduct -

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

  • 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.

    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!!";

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


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

    Thank you :)

  • 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 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.

    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 :)

  • 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.

  • 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 :)


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

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

Log in to reply