[Qt-interest] simple QSqlTableModel problem
Israel Brewster
israel at frontierflying.com
Thu Dec 18 00:48:37 CET 2008
I have done this in production several times, but this time around I
am having problems. Specifically, I have a simple application that
just opens a single window containing a QTableView, set to a
QSqlTableModel. The database is a local SQLite database. The
QTableView loads and displays the data just fine, but when I make a
change and hit enter, the change is not saved- the view just refreshes
to showing the same old data. The code I have is shown below. What am
I missing? Using Qt 4.4.3 on Mac OS 10.5.5, static built from source.
Thanks.
In main.cpp:
#include <QtGui/QApplication>
#include "dataview.h"
#include <QtGui>
#include <QtSql>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("/Users/israel/test.db");
// removed error-checking code for compactness.
dataView newView;
newView.show();
return a.exec();
}
dataview.h:
#ifndef DATAVIEW_H
#define DATAVIEW_H
#include "ui_Database.h"
#include <QtSql>
class dataView : public QDialog, private Ui::dataView
{
Q_OBJECT
public:
dataView();
private:
QSqlTableModel dataModel;
};
#endif // DATAVIEW_H
and finally, dataview.cpp:
#include "dataview.h"
#include <QtGui>
dataView::dataView()
{
setupUi(this);
dataModel.setTable("milage");
// removed error-checking code for compactness.
dataModel.select();
// removed error-checking code for compactness.
dataTable->setModel(&dataModel);
dataTable->resizeColumnsToContents();
}
-----------------------------------------------
Israel Brewster
Computer Support Technician
Frontier Flying Service Inc.
5245 Airport Industrial Rd
Fairbanks, AK 99709
(907) 450-7250 x293
-----------------------------------------------
More information about the Qt-interest-old
mailing list