[Qt-interest] Using QAbstractTableModel with Custom Class

Mandeep Sandhu mandeepsandhu.chd at gmail.com
Wed Jun 30 12:54:19 CEST 2010


On Wed, Jun 30, 2010 at 4:13 PM, Bill Moo <cppsysdev at gmail.com> wrote:
> Hello List,
>
> I have a class that does some work, and this work runs on internal threads.
> In order to keep the user informed of the progress of each instance I
> thought that by using a Model based QTableView I could eliminate some of the
> hard work.
>
> 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).
>
> So assuming for example my QMap contained wto entries what I'd want to see
> in the QTableView are two rows by x rows (with headers). Column 0 would
> display the name of the file currently being processed, the next column
> would display the number of lines to process in this file, the third column
> would display the number of rows processed so far.

This is doable.

You can subclass QAbstractTableModel for this purpose.

Override the data(const QModelIndex &index, int role) function to
return your custom values.

You can use your QMap to access the instance of the worker thread  and
return the appropriate value for the respective row/col num, as
specified in the model index passed here.

HTH,
-mandeep


>
> Is this even possible, or is it the Worker that needs to be a derivative of
> QAbstractTable | Item Model I have googled of course but I've not found
> anythign that comes close.
>
> --
> 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