[Qt-interest] [Performance] Inserting thousands of rows

André Somers andre at familiesomers.nl
Thu Jan 22 12:42:56 CET 2009


Hi,

"Stephan Rose" <kermos at somrek.net> wrote in message 
news:gl8nli$9s5$1 at eple.troll.no...
> On Thu, 2009-01-22 at 02:40 +0100, Georg Grabler wrote:
>> Hello,
>>
>>
>> I've a question about performance (or visual performance) of an
>> application
>>
>> Let's take a common QTableWidget. Let's say I'd like to insert ....
>> 10.000 rows. Now, usually my whole application (in most languages)
>> will block, until the rows are inserted. So it does in QT at the
>> moment, using a standard QT Designer form with a TreeView and a
>> TableWidget.
>>
>> Do you have any ideas to (in example) have an own thread handling the
>> QTableWidget, so the rest of the application won't block, so I can
>> still use the Menu / TreeView while the Table is loading?
>
> One way would be to create a QTimer with an interval of 0 which will
> make the timer fire it's timeout signal continuously when the
> application isn't otherwise busy. Connect a slot to that signal and have
> that slot add a few records to the table each time. When all records
> have been added simply shut off the timer.
>
> It's an easy way to get non-blocking behavior without going through all
> the work necessary for multi-threading or custom models.

Some additional notes:
* Non-blocking behaviour solutions have been described in a recent Qt 
Quarterly. See here for some solutions: 
http://doc.trolltech.com/qq/qq27-responsive-guis.html

* If possible, call setUniformRowHeights ( true ) on your view. This makes a 
*huge* difference on big views.

* Try to see if you can add the data only when needed (lazy population).

* If you really use a list or a table: try rethinking your presentation. No 
user likes to have to sift through such a huge list anyway, so if you can 
avoid presenting one you solve both a technical and a usability issue in one 
go.

* Don't add the rows to your model one-by-one, but all at the same time or 
in blocks of a reasonable size.

André
 




More information about the Qt-interest-old mailing list