Results 1 to 4 of 4

Thread: How to load items in QComboBox in a separate thread?

  1. #1
    Join Date
    Feb 2011
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default How to load items in QComboBox in a separate thread?

    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,

    Ric.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to load items in QComboBox in a separate thread?

    There is no restriction in loading the data to your model from another thread.
    The only restriction is not doing painting in worker threads.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Feb 2011
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: How to load items in QComboBox in a separate thread?

    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!

    Ric.

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to load items in QComboBox in a separate thread?

    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.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. Put in a separate thread a method of a class
    By franco.amato in forum Qt Programming
    Replies: 0
    Last Post: 19th March 2010, 23:45
  2. update widget from separate thread
    By method in forum Qt Programming
    Replies: 5
    Last Post: 10th July 2009, 14:33
  3. Accesing widgets from separate thread
    By msmihai in forum Qt Programming
    Replies: 2
    Last Post: 8th December 2008, 11:48
  4. new QWidget in separate thread
    By magland in forum Qt Programming
    Replies: 15
    Last Post: 7th February 2008, 12:32
  5. handling paintGL in a separate thread
    By al101 in forum Qt Programming
    Replies: 1
    Last Post: 15th May 2007, 17:04

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.