0

I have implemented canFetchMore, hasChildren and fetchMore in order to allow my model to be lazy loaded. It's very simple and based on QT's: http://doc.qt.io/archives/qt-4.7/itemviews-simpletreemodel.html

My problem is that in my application fetching children is not a very quick operation, it involves a few seconds of delay on the server side while it figures out who the children actually are.

I'm unsure how to deal with that. I can't have my application locking up for several seconds every time someone expands a node. I don't know how to go about making this happen in the background. If I was to create a sub-process or thread to actually do the work of retrieving the children and updating the client side data structure, how would I go about telling the model that this had successfully completed (and for the node to finally expand).

Also, is there a way to show that the node is currently in the process of loading the data in the background?

Apologies if these are stupid questions, GUI programming is still a bit of a mystery to me and I've never used QT before.

For the record, I'm using Python, but if answers are given in C++ I can understand them.

Thanks

Christophe Weis
  • 2,518
  • 4
  • 28
  • 32
dpwr
  • 2,732
  • 1
  • 23
  • 38

1 Answers1

1

If I was to create a sub-process or thread to actually do the work of retrieving the children and updating the client side data structure, how would I go about telling the model that this had successfully completed (and for the node to finally expand).

You can use signal and slots. In the thread you retrieve the data you will emit a custom signal like someDataAvailable(YourdataType) and then in the gui you will handle this signal with a slot something like handleDataReadySignal(YourdataType). The signal passes the object that you give it when emitting. Apparently you need to update the gui and the list in the handleDataReadySignal slot. Of course you need to connect the slot to the signal preferably in the constructor of the window/dialog to which the list is attached

destan
  • 4,301
  • 3
  • 35
  • 62
  • So you wouldn't use fetchmore to add items at all, but use it to emit a signal. That signal causes data collection in another thread and then it emits a signal to the GUI. The GUI then inserts rows using insertRow (this doesn't actually populate or initialise an item) then enters the actual data into that row using setData. If this is so, how do you add the items in the correct place when returning from the worker thread? According to the documentation, indexes should not be passed around as they are liable to change and there is no way of looking up an index based on the actual item of data. – dpwr Jul 12 '12 at 15:17
  • Well, maybe for this case you can need to use index to locate where to put newly arrived items. Just try it this way if it works then seek a way to implement this without passing indexes. – destan Jul 13 '12 at 13:46