[Qt-interest] simple QSqlTableModel problem

Israel Brewster israel at frontierflying.com
Fri Dec 19 01:07:53 CET 2008


Thanks for the response. Asside from the .ui file (which I've  
attached), all the code for a minimilistic example case is included in  
my message, just copy and paste into three files, named as indicated :)
-----------------------------------------------
Israel Brewster
Computer Support Technician
Frontier Flying Service Inc.
5245 Airport Industrial Rd
Fairbanks, AK 99709
(907) 450-7250 x293
-----------------------------------------------


On Dec 18, 2008, at 1:52 PM, Bill KING wrote:

> 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Database.ui
Type: application/octet-stream
Size: 1400 bytes
Desc: not available
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20081218/ba32cbad/attachment.obj 


More information about the Qt-interest-old mailing list