Results 1 to 3 of 3

Thread: Traversing QTableView

  1. #1
    Join Date
    Jul 2009
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Traversing QTableView

    Due to a school project, i wanted to do a small database program with Qt. After setting up a QTableView and its QStandardItemModel, im wondering how i can traverse for the values as i need to save the values into a text file. Preferably it traverses row by row. Thx for any info.

  2. #2
    Join Date
    May 2009
    Posts
    62
    Thanks
    2
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Traversing QTableView

    The data displayed in the QTableView is actually stored in its model. Use:

    Qt Code:
    1. QAbstractItemModel* model = tableView->model();
    2. for (int row = 1; row < model->rowCount(); ++row)
    3. {
    4. for (int column = 1; column < model->columnCount(); ++column)
    5. {
    6. QVariant itemData = model->index(row, column).data();
    7. // process data ...
    8. }
    9. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jul 2009
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Traversing QTableView

    Thx for the help.
    Cheers.

Similar Threads

  1. Replies: 5
    Last Post: 24th July 2009, 22:30
  2. Replies: 2
    Last Post: 7th June 2009, 10:47
  3. QTableView in ui with model/delegate
    By tpf80 in forum Qt Programming
    Replies: 7
    Last Post: 6th November 2008, 23:00
  4. QTableView
    By dragon in forum Qt Programming
    Replies: 0
    Last Post: 22nd September 2008, 16:53
  5. Multi-line messages in QTableView
    By Conel in forum Qt Programming
    Replies: 6
    Last Post: 13th April 2006, 13:49

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.