Qt-jambi-interest Archive, November 2007
Re: TableView w/ H2 database
Message 1 in thread
Jason wrote:
> Bump - anybody? QSqlTableModel doesn't seem to have any data.
>
> I can get my TableView showing H2 data using a regular old
> java.sql.Connection and implementing a QAbstractTableModel class. But, I
> think this is a poor hack - it only proves that my TableView seems ok.
> Obviously it would be preferable to use the QSqlTableModel.
>
Hi, Jason.
I haven't been able to reproduce the problem you are having, but I have
discovered a possible cause. It seems that there's a bug in
QAbstractItemView which could result in your model being garbage
collected while it is being presented in the view.
Could you try giving the QSqlTableModel a parent as a possible work-around?
QSqlTableModel model = new QSqlTableModel(ui.tblContacts, db);
The parent should make sure the model is not marked by the garbage
collector. If this does not work, please also try moving the declaration
of "model" to the global scope so you can be sure Java will have a
reference to the object throughout the execution of the application.
The bug in QAbstractItemView will be fixed for the next release of Qt Jambi.
-- Eskil