Results 1 to 2 of 2

Thread: QTableWidgetItem::setData crashes

  1. #1
    Join Date
    Apr 2011
    Posts
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default QTableWidgetItem::setData crashes

    Hi Gurus,

    Can anybody tell me what is wrong with this code?

    Qt Code:
    1. QHash<QString, double> results = ReturnResults();
    2. int row = 0;
    3. QHashIterator<QString, double> i(results);
    4. while (i.hasNext()) {
    5. i.next();
    6. QVariant key;
    7. key = i.key();
    8. QTableWidgetItem *newLine = tblResult->item(row,0);
    9. newLine->setData(Qt::UserRole,key);
    10.  
    11.  
    12. cout << i.key() << ": " << i.value() << endl;
    13. row++;
    14. }
    To copy to clipboard, switch view to plain text mode 

    Any help will be much appreciated.

    RT

  2. #2
    Join Date
    Sep 2009
    Location
    Aachen, Germany
    Posts
    60
    Thanks
    2
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTableWidgetItem::setData crashes

    The QTableWidgetItem has to be created by hand, so the first question would be wether you did that. Otherwise QTableWidget::item returns 0.
    If the code you posted is supposed to create the table, it would have to look like this:

    Qt Code:
    1. QHash<QString, double> results = ReturnResults();
    2. tblResult->setRowCount(results.size());
    3. int row = 0;
    4. QHashIterator<QString, double> i(results);
    5. while (i.hasNext()) {
    6. i.next();
    7. QVariant key;
    8. key = i.key();
    9. newLine->setData(Qt::UserRole,key);
    10. tblResult->setItem(row, 0, newLine);
    11.  
    12. cout << i.key() << ": " << i.value() << endl;
    13. row++;
    14. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. QTableWidgetItem setData crashes everytime.
    By Wing_Zero in forum Qt Programming
    Replies: 2
    Last Post: 16th August 2010, 19:59
  2. QTableWidgetItem: setData or setText?
    By mattc in forum Qt Programming
    Replies: 1
    Last Post: 5th January 2010, 18:34
  3. QSqlTableModel and possible bug with setData?
    By sylvainb in forum Qt Programming
    Replies: 2
    Last Post: 25th February 2009, 21:43
  4. setData()
    By starcontrol in forum Qt Programming
    Replies: 2
    Last Post: 2nd May 2008, 08:54
  5. setData()
    By coderbob in forum Qt Programming
    Replies: 4
    Last Post: 28th February 2008, 12:51

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.