| Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date | |
| All threads index page 1 | |
I'm not quite sure of the code to required to do this, but I have a QSqlQueryModel plugged into a QSortFilterProxyModel that displays in a QTreeView. What's the proper way to refresh the data displayed from the database? Thanks, -- [ signature omitted ]
Attachment:
signature.asc
Description: PGP signature
On 02.12.07 20:28:10, Cody Harris wrote: > I'm not quite sure of the code to required to do this, but I have a > QSqlQueryModel plugged into a QSortFilterProxyModel that displays in a > QTreeView. What's the proper way to refresh the data displayed from > the database? As far as I can see: calling setQuery on the QSqlQueryModel. Andreas -- [ signature omitted ]
On Mon, 3 Dec 2007 01:51:35 +0100 Andreas Pakulat <apaku@xxxxxx> wrote: > On 02.12.07 20:28:10, Cody Harris wrote: > > I'm not quite sure of the code to required to do this, but I have a > > QSqlQueryModel plugged into a QSortFilterProxyModel that displays > > in a QTreeView. What's the proper way to refresh the data > > displayed from the database? > > As far as I can see: calling setQuery on the QSqlQueryModel. I'm not exactly sure about the internal representation on how stuff works, but does setQuery call anything I can call to refresh, or is the best way to save my SQL query, and then just call it again with the string I provided earlier. > > Andreas > -- [ signature omitted ]
Attachment:
signature.asc
Description: PGP signature
> -----Original Message----- > From: Cody Harris [mailto:charris@xxxxxxxxxx] > Sent: Sunday, December 02, 2007 5:03 PM > To: qt-interest@xxxxxxxxxxxxx > Subject: Re: Refreshing QTreeView, QSortFilterProxyModel, and > QSqlQueryModel > > On Mon, 3 Dec 2007 01:51:35 +0100 > Andreas Pakulat <apaku@xxxxxx> wrote: > > > On 02.12.07 20:28:10, Cody Harris wrote: > > > I'm not quite sure of the code to required to do this, but I have a > > > QSqlQueryModel plugged into a QSortFilterProxyModel that displays > > > in a QTreeView. What's the proper way to refresh the data > > > displayed from the database? > > > > As far as I can see: calling setQuery on the QSqlQueryModel. > > I'm not exactly sure about the internal representation on how stuff > works, but does setQuery call anything I can call to refresh, or is the > best way to save my SQL query, and then just call it again with the > string I provided earlier. Usually, you shouldn't have to do this... If your models are correctly connected, and modifications are calling the proper data changed methods on the model, the correct signals are emitted that will cause the view to update the correct area. However, calling reset on the model will force a full refresh, which is NOT what you usually want. When I have used older versions of QT, which had a minor bug or two in the refresh, I would sometimes explicitly call the views dataChanged slot... Scott -- [ signature omitted ]
On Sun, 2 Dec 2007 17:26:18 -0800 "Scott Aron Bloom" <Scott.Bloom@xxxxxxxxxxxx> wrote: > > > > -----Original Message----- > > From: Cody Harris [mailto:charris@xxxxxxxxxx] > > Sent: Sunday, December 02, 2007 5:03 PM > > To: qt-interest@xxxxxxxxxxxxx > > Subject: Re: Refreshing QTreeView, QSortFilterProxyModel, and > > QSqlQueryModel > > > > On Mon, 3 Dec 2007 01:51:35 +0100 > > Andreas Pakulat <apaku@xxxxxx> wrote: > > > > > On 02.12.07 20:28:10, Cody Harris wrote: > > > > I'm not quite sure of the code to required to do this, but I > > > > have > a > > > > QSqlQueryModel plugged into a QSortFilterProxyModel that > > > > displays in a QTreeView. What's the proper way to refresh the > > > > data displayed from the database? > > > > > > As far as I can see: calling setQuery on the QSqlQueryModel. > > > > I'm not exactly sure about the internal representation on how stuff > > works, but does setQuery call anything I can call to refresh, or is > the > > best way to save my SQL query, and then just call it again with the > > string I provided earlier. > > Usually, you shouldn't have to do this... If your models are correctly > connected, and modifications are calling the proper data changed > methods on the model, the correct signals are emitted that will cause > the view to update the correct area. > There is no means, that at least I know of, for the MySQL server to pass along information that there has been an update in a table, so the only way I know to allow a refresh is to dump the contents and repopulate the widget. I'm not sure if this is the best way to do this. I can call reset, but is that the best? > > However, calling reset on the model will force a full refresh, which > is NOT what you usually want. > > When I have used older versions of QT, which had a minor bug or two in > the refresh, I would sometimes explicitly call the views dataChanged > slot... > When calling reset, setQuery, or through some other means? > > Scott > > -- > To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx > with "unsubscribe" in the subject or the body. List archive and > information: http://lists.trolltech.com/qt-interest/ -- [ signature omitted ]
Attachment:
signature.asc
Description: PGP signature
> There is no means, that at least I know of, for the MySQL server to > pass along information that there has been an update in a table, so the > only way I know to allow a refresh is to dump the contents and > repopulate the widget. I'm not sure if this is the best way to do > this. I can call reset, but is that the best? So the beforeUpdate, primeInsert etc etc signals from the SQL model is not being sent? Unfortunately, I don't use QT with SQL enough to help there... Usually this is an issue in the model, which is not emitting the proper "my data has changed" notfications... My question to you... How do you know on the QT side, that the MySQL server has changed? Or are you just doing a timed update? > > When I have used older versions of QT, which had a minor bug or two in > > the refresh, I would sometimes explicitly call the views dataChanged > > slot... > > > When calling reset, setQuery, or through some other means? Sorry should have been clearer... There is a method on QAbstractItemView called QAbstractItemView::dataChanged with a topLeft and bottomRIght parameters. I have had to derive from a table view before to simply expose this protected method. Scott -- [ signature omitted ]
On Sun, 2 Dec 2007 19:36:15 -0800 "Scott Aron Bloom" <Scott.Bloom@xxxxxxxxxxxx> wrote: > > There is no means, that at least I know of, for the MySQL server to > > pass along information that there has been an update in a table, so > the > > only way I know to allow a refresh is to dump the contents and > > repopulate the widget. I'm not sure if this is the best way to do > > this. I can call reset, but is that the best? > > So the beforeUpdate, primeInsert etc etc signals from the SQL model is > not being sent? > > Unfortunately, I don't use QT with SQL enough to help there... Usually > this is an issue in the model, which is not emitting the proper "my > data has changed" notfications... > > My question to you... How do you know on the QT side, that the MySQL > server has changed? Or are you just doing a timed update? > Well, the program will be networked, and when another client changes the database in the network, a message will be sent to my application, which does a refresh on the database. I don't have that functionality yet, but I've been using a command line interface to MySQL to insert tables. So, no when I insert data into the SQL server, nothing in my interface is changing. I have QSqlQueryModel subclassed out, but it doesn't do anything but provide me with a slot called pReset() that now reissues the setQuery() method. pReset() triggered by when I (or the user), clicks "Force Database Rescan", for those times it just makes sense. Before I added this button, that called setQuery(), the only way to see my changes was to close and re-open. > > > > > When I have used older versions of QT, which had a minor bug or > > > two > in > > > the refresh, I would sometimes explicitly call the views > > > dataChanged slot... > > > > > When calling reset, setQuery, or through some other means? > > Sorry should have been clearer... There is a method on > QAbstractItemView called QAbstractItemView::dataChanged with a > topLeft and bottomRIght parameters. > > I have had to derive from a table view before to simply expose this > protected method. > I read about that, but I'm not sure from where I would get the bottomRight parameter. > > Scott > > -- > To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx > with "unsubscribe" in the subject or the body. List archive and > information: http://lists.trolltech.com/qt-interest/ -- [ signature omitted ]
Attachment:
signature.asc
Description: PGP signature
On mandag den 3. December 2007, Scott Aron Bloom wrote: > > There is no means, that at least I know of, for the MySQL server to > > pass along information that there has been an update in a table, so > > the > > > only way I know to allow a refresh is to dump the contents and > > repopulate the widget. I'm not sure if this is the best way to do > > this. I can call reset, but is that the best? > > So the beforeUpdate, primeInsert etc etc signals from the SQL model is > not being sent? > > Unfortunately, I don't use QT with SQL enough to help there... Usually > this is an issue in the model, which is not emitting the proper "my data > has changed" notfications... > > My question to you... How do you know on the QT side, that the MySQL > server has changed? Or are you just doing a timed update? This is a MySQL driver problem (and it's the same for all other database drivers). They don't report on changes to the tables and there is no way to get notifications about these. If you want those, you have to build a layer around the database that your system will talk to. This was exactly the reason I built QRPC (the Qt networking formerly know as TC Orb). That one gives me signals and slots across network connections, and I used it to make a three tier system with a server that took care of the actual database connection. Calling reset() in QSqlQueryModel doesn't work in this particular case, since it doesn't update the table info from the server. It only makes the views update their information. Instead, you call setQuery again (as someone already noted). Bo. -- [ signature omitted ]
Hi Cody, I assume that you just want to fetch the data from the database again after it is updated externally. Have you tried myQueryModel->query()->exec() ? Hope that helps, Tony Rietwyk > -----Original Message----- > From: Cody Harris [mailto:charris@xxxxxxxxxx] > Sent: Monday, 3 December 2007 11:28 > To: qt-interest@xxxxxxxxxxxxx > Subject: Refreshing QTreeView, QSortFilterProxyModel, and > QSqlQueryModel > > > I'm not quite sure of the code to required to do this, but I have a > QSqlQueryModel plugged into a QSortFilterProxyModel that displays in a > QTreeView. What's the proper way to refresh the data displayed from > the database? > > Thanks, -- [ signature omitted ]