Drenghel
Drenghel

Reputation: 59

Is an QAbstractItemModel subclass thread safe?

Hello good ppl from SO !

Today I have been questioning myself a lot about what I was trying to implement.

It comes to this, I'm trying code some kind a of terminal with Qt, which will be used to display messages from different parts of my application.

Right now I implemented a model class (derived from QAbstractTableModel) that represent a QList of theses message lines and was intending to map them to the widget in my Terminal window ( DataWidgetMapper was considered ).

But then it hit me, what if different parts of my app was trying to add at the same time new messages ?
Can it even possibly happen ?
Is implementing BeginInsertRow related to safe guarding theses kind of things ?


Long story short I'm confused. I can't find much intel on my own. So I'm starting to wonder if I'm even doing this the right way.

I'm a bit of a new guy in the Qt world.

Thanks in advance :)

Upvotes: 0

Views: 511

Answers (1)

goug
goug

Reputation: 2444

Since you're implementing your own model on top of QAbstractItemModel, the determination of whether it's thread-safe is up to you. You have to design your own internal data model, so the methods that change and access data within the model are your own. You have complete control of their contents so you can add whatever thread-locking mechanism you need to ensure that different threads can't both update and access data at the same time. All of the QAbstractItemModel methods that provide data access end up calling your derived methods.

Upvotes: 2

Related Questions