[Qt-interest] Using QAbstractTableModel with Custom Class
Carsten Breuer
CarstenBreuerQt at textwork.de
Thu Jul 1 00:19:29 CEST 2010
Hi Bill,
hi all,
> What I want to do a to create a QMap < int, Worker * > where the int is
> the row number in view and the Worker * is an instance my class that
> does all the hard work. However, what I can't get my head round
> (assuming it is even possible) is how do I display the Worker's internal
> member variable values in the grid? (as some of these are updated by the
> internal processes).
The problem here is IMO thread synchronisation.
Your workers need a event loop to receive signals and
the connection must be made with Qt::QueuedConnection.
The good thing is that the code is executed in the receivers
thread, so you can call dataChanged within that call.
I would do the following:
- Create a new class derived from QAbstractItemModel, that
holds all work data of the different threads.
- Create a slot in that class, so that your worker threads
can fire data changes.
- Connect the model to the view with setModel.
- If the slot is called from the worker threads,
update work data and fire dataChanged.
The view will start asking your model for
new data.
Attention: You have to deal with the different roles!
The function data() of the model do (depending on
the role) much more then even sends the data to the view.
There are also declarative roles!
BTW: Worker threads in a QMap sounds a bit advanced
in my ears ;-).
Best Regards,
Carsten
>
> --
> Bill
>
>
>
>
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
More information about the Qt-interest-old
mailing list