model->setFilter("id is not null");
class Model : public QSqlTableModel { Q_OBJECTpublic: Model(QObject* parent=0,QSqlDatabase db=QSqlDatabase());public slots: bool submit(); bool submitAll();};
Model::Model(QObject *parent,QSqlDatabase) : QSqlTableModel(parent) {}bool Model::submit() { bool ret = QSqlTableModel::submit(); if (!ret) qDebug() << Model::lastError().text(); return ret;}bool Model::submitAll() { bool ret = QSqlTableModel::submitAll(); if (!ret) qDebug() << Model::lastError().text(); return ret;}
C++ (Qt)//model.hclass Model : public QSqlTableModel { Q_OBJECTpublic: Model(QObject* parent=0,QSqlDatabase db=QSqlDatabase());public slots: bool submit(); bool submitAll();signals: void sqlError(const QString &);};
C++ (Qt)//model.cppModel::Model(QObject *parent,QSqlDatabase) : QSqlTableModel(parent) {} bool Model::submit() { bool ret = QSqlTableModel::submit(); if (!ret) emit sqlError(QSqlTableModel::lastError().text()); return ret;} bool Model::submitAll() { bool ret = QSqlTableModel::submitAll(); if (!ret) emit sqlError(QSqlTableModel::lastError().text()); return ret;}