[Qt-interest] Using QAbstractTableModel with Custom Class
Bill Moo
cppsysdev at gmail.com
Wed Jun 30 13:44:02 CEST 2010
On Wed, Jun 30, 2010 at 11:54 AM, Mandeep Sandhu <
mandeepsandhu.chd at gmail.com> wrote:
> 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.
> >
>
Hi thanks for that, I've actually got a copy of the book itself, and this
what I've been using, but it doesn't show you what I want to do it only show
'basic' implementations but nothing using custom classes via pointers.
All I get in my models view is a single row single column view, no headers
or anything.
Are there any concrete examples demonstrating this out there that anyone
knows of? The more and more I look at this the more I'm becoming convinced
that it is the Worker class that needs to be derived from
QAbstractTableModel. But maybe I'm wrong.
--
Bill
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100630/5869af7f/attachment.html
More information about the Qt-interest-old
mailing list