Results 1 to 6 of 6

Thread: Model-View: how to get the data from my selected rows

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2008
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Model-View: how to get the data from my selected rows

    Qt Code:
    1. QModelIndexList listModelIndex = selectionModel->selectedRows();
    2. for (QModelIndexList::Iterator iter = listModelIndex.begin(); iter != listModelIndex.end (); ++iter, ++pChan) {
    3. index = *iter;
    4. row = index.row();
    5. pChan->m_channel = modelChannel->data(modelChannel->index(row, 0), Qt::DisplayRole).toUInt();
    6. pChan->m_isRecorded = modelChannel->data(modelChannel->index(row, 1), Qt::DisplayRole).toUInt();
    7. pChan->m_isPrioritied = modelChannel->data(modelChannel->index(row, 2), Qt::DisplayRole).toUInt();
    8. }
    To copy to clipboard, switch view to plain text mode 

    First I get the list of the selected rows; then I want to get the index of every row. However because the data have been sorted, so the getted row-index in Line L4 is not the one, which I want to get. I want get the index of the selected one in view by my eyes, not the one in the model in computer mem!

    Maybe it is not easy to understand only by my above words. So you can try the example of QT4.4.X\examples\itemviews\addressbook. First you input 3 names and addresses one by one, such as <Alice, anywhere>, <Bring, anywhere> and <John, anywhere>, then you try to change the Alice' adress. You will find it can not to be changed!
    Last edited by jpn; 6th August 2008 at 18:13. Reason: missing [code] tags

Similar Threads

  1. Data model
    By steg90 in forum Qt Programming
    Replies: 3
    Last Post: 17th September 2007, 12:14
  2. Table Model / View Problem -- Data Not Displaying
    By jhendersen in forum Qt Programming
    Replies: 1
    Last Post: 22nd April 2007, 06:45
  3. Model, View and Proxy
    By No-Nonsense in forum Qt Programming
    Replies: 2
    Last Post: 21st November 2006, 08:50
  4. Replies: 6
    Last Post: 20th April 2006, 10:23
  5. Model, view, resize to show all data
    By jcr in forum Qt Programming
    Replies: 2
    Last Post: 17th April 2006, 20:59

Tags for this Thread

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.