[Qt-interest] simple QSqlTableModel problem

Bill KING bill.king at trolltech.com
Thu Dec 18 23:52:11 CET 2008


A bit busy atm, and haven't got any quick answers for you. If you can
give me a minimalist set of code that can be put into the autotests, I
can add it in and it'll get fixed as soon as I can.

QSqlTableModel is on my list to go through and clean up, but... it's a
long list with a lot of bugs to work through ;)

Israel Brewster wrote:
> One additional piece of information here: if I use a QSqlQuery to  
> execute a command directly, it works fine. It's just the  
> QSqlTableModel that appears to be messed up, and only when sending  
> data back to the database- it caches the changes fine until it tries  
> to submit them.
>
> -----------------------------------------------
> Israel Brewster
> Computer Support Technician
> Frontier Flying Service Inc.
> 5245 Airport Industrial Rd
> Fairbanks, AK 99709
> (907) 450-7250 x293
> -----------------------------------------------
>
>
> On Dec 17, 2008, at 2:48 PM, Israel Brewster wrote:
>
>   
>> 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
>> -----------------------------------------------
>>
>>
>> _______________________________________________
>> Qt-interest mailing list
>> Qt-interest at trolltech.com
>> http://lists.trolltech.com/mailman/listinfo/qt-interest
>>     
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
>   


-- 
Bill King, Software Engineer
Qt Software, Nokia Pty Ltd
Brisbane Office




More information about the Qt-interest-old mailing list