Results 1 to 4 of 4

Thread: QTableView Model Help

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2008
    Location
    UK
    Posts
    35
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QTableView Model Help

    Hi,

    I'm having some problems working out how to implement the data() function from QAbstractTableModel for use in a QTableView model.

    My data is stored in a large vector, that the model (which is read only) has a pointer to, I set up the headerData() function, so all the column names are correct and that works fine. rowCount and ColumnCount are also in my class, correct i think.

    I have 4 columns, and x number or rows, so i just need some help with returning the correct data from the data() function.

    Here is my code, im basically not sure how i use the index and role values in order to know a) which column the data is from, and b) the row number. I need these 2 values in order to know which data to get from the data vector. For example if its from column 2 and row 5, i know i need to return the subject from element 5 in the vector. Is it as simple as role is the column and index is the row?

    Qt Code:
    1. QVariant QueueModel::data(const QModelIndex &index, int role) const
    2. {
    3. if (!index.isValid() || role != Qt::DisplayRole)
    4. return QVariant();
    5.  
    6. //return ....
    7. }
    To copy to clipboard, switch view to plain text mode 

    Also, do i have to do anything special to keep the view updating? i.e if i change a value in the data vector and another point in my program (outside of the model), will the view just update automatically?

    Thanks alot for any tips,

    Jack
    Last edited by tntcoda; 22nd June 2008 at 15:33.

Similar Threads

  1. Replies: 6
    Last Post: 22nd November 2011, 03:53
  2. QTableView sorting when using a model
    By steg90 in forum Qt Programming
    Replies: 2
    Last Post: 12th June 2008, 13:13
  3. Help choosing a model type for QTableView
    By goes2bob in forum Newbie
    Replies: 1
    Last Post: 10th March 2008, 02:22
  4. Replies: 5
    Last Post: 16th May 2007, 11:03
  5. Replies: 9
    Last Post: 7th November 2006, 15:10

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.