PDA

View Full Version : Subclassiıng QAbstractItemModel for a thread-safe tree model



fakefish
17th February 2010, 08:19
Hello,
I needed a thread-safe treemodel, so I intended to subclass QAbstractItemModel for the purpose.
But I have faced some problems. If any one can help me to overcome them, I will be glad.

Problems:
1. some public methods such as index, parent, rowxount, etc. are called by QAbstractItemModel when I called beginInsertRows, etc. So I cannot mutex these functions correctly. (Actually I use QReadWriteLocker)

2. If I set the model from UI thread the endInsertRows calls treeView's methods directly. (which means treeView's call to Data appears below my insertItem method in the call stack). So the system is locked.

3. In the index function I am setting (void *) by using createIndex function of QAbstractItemModel, but in one data call an invalid pointer is recieved. Dıes anyone jnows what can cause this.

Best regards,

TMan
17th February 2010, 14:53
I can't really imagine why you would want to use a thread-safe tree model. I don't even know if QAbstractItemModel is thread safe. Wouldn't it be easier to create a thread safe interface to qtreemodel?

fakefish
18th February 2010, 07:03
The problem is;
I have lots (hundreds per second) of message(each message contains multiple operations on the model) coming from network, and need to write them in more than 30 models When I do it on UI main thread therfe occurs a freezing problem on GUI.
And even this doesnot guarentee that the view will not request an invalid index. So I required a thread-safe model if possible.

By the way QAbstactItemModel is not thread-safe.

regards,

jerobarraco
11th October 2012, 18:39
so there isnt actually any usefull reply?
:(
i have a similar situation..
I find that using a model to centralize the data-handling is of little use if, when i really need to centralize the handling of data (ie network operations or other clients) the model can't do it.

wysota
11th October 2012, 19:47
And where are threads in all this?