[Qt-interest] Asynchronous loading?
Christopher Rasch-Olsen Raa
christopher at technophile.info
Tue Jul 14 09:43:43 CEST 2009
Hi,
On Tuesday 14 July 2009 09:45:13 you wrote:
> Hi,
>
> On Tuesday 14 Jul 2009 08:21:02 Christopher Rasch-Olsen Raa wrote:
> > Hi,
> >
> > I have an application that consist of a QTabWidget. Each of the tabs have
> > a widget that have to fetch a fair amount of data from an external
> > database. At the present time the program takes a lot of time to start
> > because of all of them getting stuff at the same time.
> >
> > What I'd like to see happen is that the program first loads the data for
> > the active tab, and then proceeds to load data for the other "hidden"
> > ones. Do you have any pointers on how to implement this somewhat cleanly
> > without blocking the GUI?
> >
> > Oh, and btw; at the present time the loading happens in the constructor
> > of the various widgets placed in the QTabWidget. It's no problem changing
> > this.
>
> You have a couple options to try:
>
> (i) Do not load the data in the constructor. Instead do the loading in the
> QWidget::showEvent() so that you only load the data for a particular tab-
> page's widget when it is actually shown. This should reduce the time your
> GUI is busy loading data at any one time by a factor of N where N is the
> number of tabs that load data.
This is a good starting-point I think.
> If this is still not acceptable then:
>
> (ii) Use a worker thread to load your data in the background. When the
> tread has each page's data it can emit a signal which you can connect to a
> slot in your dialog. The slot can then populate the widgets with the data.
How would this work in a situation where the majority of the widgets are
QTableViews connected to a QSqlTableModel? No problems or would something (eg.
the tablemodel) get cranky if placed in a separate thread?
Thanks for the input. :)
--
Christopher
More information about the Qt-interest-old
mailing list