Results 1 to 2 of 2

Thread: Filling QTreeWidget / Using QTreeView

  1. #1

    Default Filling QTreeWidget / Using QTreeView

    I am not totally new to Qt but not as experienced as I like to be.

    Thing is, I have a QTreeWidget and I want to add numerous QTreeWidgetItems to it.
    This is rather timeconsuming and I don't want the app to freeze. So I thought about extracting the filling of the QTreeWidget to a seperate thread (which seems to be a bad idea). When running the programm averything works fine. Problem is I get the output:
    'QObject::startTimer: timers cannot be started from another thread'.
    Ok not so good. It's a warning and I want to take it serious.

    I found that it is bad to interact with the QTreeWidget since it was created in another thread.

    Short example:
    ThreadA creates QTreeWidget.
    ThreadB gets reference to QTreeWidget and adds QTreeWidgetItems. (This causes an output as mentioned above)
    ThreadB resizes the columns of QTreeWidget. (Another output as mentioned above)

    Would it be better to use QTreeView/QAbstractItemModel or something equal to do the trick?

    Or should I step back from filling a QTreeWidget in a different thread?
    I could get the data I need for filling the treewidget in a seperate thread and than use this data to fill the treewidget in the main thread.

    Could I use a View/Model structure for this approach or would there be the same problem as I have right now?

    Any hints will be appreciated.

  2. #2

    Default Re: Filling QTreeWidget / Using QTreeView

    Here I am again.

    Think I found a solution to my problem.
    I do the adding of the Treewidgets in the main thread and the collection of data in another thread.
    When the collecting of data is finished a signal is emmited with all the QTreeWidgetItems in a QList. (QList<QTreeWidgetItem*>).
    In the main thread a slot is called which gets the list and adds it to the QTreeWidget. (addTopLevelItems())

    No output which should be of any concern.

Similar Threads

  1. QProgressBar in QTreeWidget?
    By lvi in forum Qt Programming
    Replies: 5
    Last Post: 3rd September 2008, 19:48
  2. QTreeWidget or QTreeView ?
    By vieraci in forum Qt Programming
    Replies: 3
    Last Post: 7th November 2007, 09:31
  3. resizing a QTreeWidget
    By drhex in forum Qt Programming
    Replies: 6
    Last Post: 27th October 2006, 22:32
  4. QTreeView / QTreeWidget
    By morty in forum Qt Programming
    Replies: 4
    Last Post: 8th October 2006, 00:40
  5. few questions related to QTreeWidget
    By prakash in forum Qt Programming
    Replies: 9
    Last Post: 10th March 2006, 07:32

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.