View Full Version : How to load items in QComboBox in a separate thread?

21st February 2011, 10:36
Good morning,

I have a window where I have several qcombobox instances loading the list of possible values from a custom DB.

When I test the GUI with a small dataset, everything is fine.

But then when I use my GUI in production with our real DB, every combobox needs to load up to 70k values, and the window takes up to 15 seconds to show up.

I would like to load data in the comboboxes in separate threads, to let the user enter other fileds in the window, while the threads fetch the data from the custom DB and load them into the comboboxes.

But I didn't find a way to do it.

Any help or hint is really really welcome!! :-)

Thanks a lot for your help, and have a nice day,


21st February 2011, 11:36
There is no restriction in loading the data to your model from another thread.
The only restriction is not doing painting in worker threads.

21st February 2011, 14:26
Hi high_flyer, thanks for your answer.

Actually in this code I don't use a model for my comboboxes, I simply use addItem().

Does your answer mean that I should use "combobox->addItem( listofitems[item] )" outside the thread, while I can use the worker thread to fetch the items from the DB and put them in the "listofitems" list?

Might you point to me a tutorial or a snippet about this use-case of combobox?

Many thanks again! :)


21st February 2011, 14:33
In that case, you can fill your item list in a worker thread, and once it's full, you can fill the combobox in the GUI thread from the item list or if you use QStringList you can use insertItems().

Might you point to me a tutorial or a snippet about this use-case of combobox?
There is nothing specific to a combobox with this.
Its the simplest worker thread scenario.
Read the QThread documentation, or QtConcurrent - there are examples there too.