[Qt-interest] Fwd: Re: Asynchronous loading?

Sean Harmer sean.harmer at maps-technology.com
Tue Jul 14 09:46:05 CEST 2009


Oops I meant to send this to the list. Sorry for replying privately.

Sean
----------  Forwarded Message  ----------

Subject: Re: [Qt-interest] Asynchronous loading?
Date: Tuesday 14 Jul 2009
From: Sean Harmer <sean.harmer at maps-technology.com>
To: christopher at technophile.info

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.

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.

HTH,

Sean


-------------------------------------------------------



More information about the Qt-interest-old mailing list