Results 1 to 3 of 3

Thread: QTableView - get value forom Item

  1. #1
    Join Date
    Feb 2009
    Location
    Bydgoszcz, Poland
    Posts
    16
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QTableView - get value forom Item

    Hi.

    I have some tables QTableView, I shown in this QTableView a table from my database. I do not generally been the case with the larger problems. And I did this:

    Qt Code:
    1. QSqlTableModel *model = new QSqlTableModel(ui->table,db);
    2.  
    3. // Wybór tablicy danych
    4. model->setTable("testowa");
    5. model->select();
    6.  
    7. ui->table->setModel(model);
    To copy to clipboard, switch view to plain text mode 

    I would to be able to get the contents (value) of a cell.

    I hope that I wrote well ( in English )

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTableView - get value forom Item

    there are two ways
    1. using QAbstractItemModel::data method
    Qt Code:
    1. ...
    2. int row = 0;
    3. int column = 0;
    4. model->data(model->index(row, column), Qt::DisplayRole);
    5. ...
    To copy to clipboard, switch view to plain text mode 
    2. using QSqlQueryModel::record
    Qt Code:
    1. ...
    2. int row = 0;
    3. int column = 0;
    4. model->record(row).value(column);
    5. ...
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. The following user says thank you to spirit for this useful post:

    bigkoma (3rd February 2009)

  4. #3
    Join Date
    Feb 2009
    Location
    Bydgoszcz, Poland
    Posts
    16
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableView - get value forom Item

    This is what I meant.

    Thanks

Similar Threads

  1. View, Scene, Item and thread??
    By dungsivn in forum Qt Programming
    Replies: 5
    Last Post: 20th August 2008, 19:21
  2. Item Delegate Painting
    By stevey in forum Qt Programming
    Replies: 3
    Last Post: 9th May 2008, 07:37
  3. QTableView - data() - item
    By starcontrol in forum Qt Programming
    Replies: 1
    Last Post: 11th April 2008, 14:41
  4. Getting item from QTableView when clicked on
    By steg90 in forum Qt Programming
    Replies: 3
    Last Post: 23rd May 2007, 11:58
  5. Dragging an item from QTableView to a QPushButton
    By steg90 in forum Qt Programming
    Replies: 2
    Last Post: 23rd May 2007, 11:57

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.