RolandHughes
13th November 2008, 22:48
Hello,
According to the documentation found here:
http://doc.trolltech.com/4.3/qsqlquerymodel.html#public-functions
I should be able to do the following:
QSqlDatabase db = QSqlDatabase::database("xpns");
tableModel = new QSqlRelationalTableModel(this, db);
tableModel->setTable("expenses");
tableModel->setRelation(tableModel->fieldIndex("category"),
QSqlRelation("categories", "category", "category"));
tableModel->setRelation(tableModel->fieldIndex("payee"),
QSqlRelation("payees", "payee", "payee"));
tableModel->setSort(tableModel->fieldIndex("tran_dt"), Qt::AscendingOrder);
tableModel->setQuery( QSqlQuery("SELECT tran_dt, category, tax_ded, payee, amount FROM expenses;", db));
tableModel->select();
You get the following error when you compile:
/usr/include/qt4/QtSql/qsqltablemodel.h: In constructor ‘XpnsForm::XpnsForm(int, int, QWidget*)’:
/usr/include/qt4/QtSql/qsqltablemodel.h:129: error: ‘void QSqlTableModel::setQuery(const QSqlQuery&)’ is protected
xpnsform.cpp:89: error: within this context
Is this just a documentation bug? I need to exclude a serial key since the data mapper appears to be trying to update it. If I take the tran_id column off the table things appear to work, so, I was looking for a simple way to exclude it from the select.
According to the documentation found here:
http://doc.trolltech.com/4.3/qsqlquerymodel.html#public-functions
I should be able to do the following:
QSqlDatabase db = QSqlDatabase::database("xpns");
tableModel = new QSqlRelationalTableModel(this, db);
tableModel->setTable("expenses");
tableModel->setRelation(tableModel->fieldIndex("category"),
QSqlRelation("categories", "category", "category"));
tableModel->setRelation(tableModel->fieldIndex("payee"),
QSqlRelation("payees", "payee", "payee"));
tableModel->setSort(tableModel->fieldIndex("tran_dt"), Qt::AscendingOrder);
tableModel->setQuery( QSqlQuery("SELECT tran_dt, category, tax_ded, payee, amount FROM expenses;", db));
tableModel->select();
You get the following error when you compile:
/usr/include/qt4/QtSql/qsqltablemodel.h: In constructor ‘XpnsForm::XpnsForm(int, int, QWidget*)’:
/usr/include/qt4/QtSql/qsqltablemodel.h:129: error: ‘void QSqlTableModel::setQuery(const QSqlQuery&)’ is protected
xpnsform.cpp:89: error: within this context
Is this just a documentation bug? I need to exclude a serial key since the data mapper appears to be trying to update it. If I take the tran_id column off the table things appear to work, so, I was looking for a simple way to exclude it from the select.