Results 1 to 1 of 1

Thread: [SOLVED] QTableWidget can not add item correctly

  1. #1
    Join Date
    Jun 2009
    Location
    Krakow, Poland
    Posts
    28
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default [SOLVED] QTableWidget can not add item correctly

    HI
    I getting data from data base and save it in QList<Storage> listStorage, where
    Qt Code:
    1. struct Storage{
    2. QString Name;
    3. double Price;
    4. double TaxValue;
    5. int IdItem;
    6. etc...
    7. }
    To copy to clipboard, switch view to plain text mode 
    This is how I'm feeding list of storage
    Qt Code:
    1. for(int i = 0; i < records.count(); i++)
    2. {
    3. Storage st;
    4. st.Name = records[i].value("Name").toString();
    5. st.Price = records[i].value("Price").toDouble();
    6. st.TaxValue = records[i].value("TaxValue").toDouble();
    7.  
    8. listStorage.append(st);
    9. }
    To copy to clipboard, switch view to plain text mode 
    At the end, when all sql queries are executed, I'm trying to feed my QTableWidget:
    Qt Code:
    1. ui->tblStorage->setRowCount(records.count());
    2. for(int i = 0; i < records.count(); i++){
    3. ui->tblStorage->setItem(i,0, new QTableWidgetItem(listStorage.at(i).Name));
    4. ui->tblStorage->setItem(i,1, new QTableWidgetItem(QString::number(listStorage.at(i).TaxValue)));
    5. ...
    6. ui->tblStorage->setItem(i,7, new QTableWidgetItem(QString::number(listStorage.at(i).Price)));
    7. }
    To copy to clipboard, switch view to plain text mode 

    All columns are being inserted correctly, bu on one "Price" I'm getting error:
    Qt Code:
    1. QTableWidget: cannot insert an item that is already owned by another QTableWidget
    To copy to clipboard, switch view to plain text mode 

    What is wrong?


    PS: I found the issue. I have method that is being executed when one of cell in table change value.
    This method is recalculating items and makes this error.
    Last edited by porterneon; 1st August 2011 at 20:53. Reason: found solution

Similar Threads

  1. QTableWidget NW corner header item?
    By McKee in forum Qt Programming
    Replies: 9
    Last Post: 31st May 2012, 00:44
  2. Item edit in QTableWidget
    By manmohan in forum Newbie
    Replies: 3
    Last Post: 29th April 2011, 17:56
  3. Manage correctly QListView item
    By noct in forum Newbie
    Replies: 3
    Last Post: 26th November 2010, 09:34
  4. QTableWidget::item to Double?
    By Afflicted.d2 in forum Qt Programming
    Replies: 2
    Last Post: 30th October 2006, 07:23
  5. QTableWidget item checkable and combo?
    By darpan in forum Qt Programming
    Replies: 1
    Last Post: 10th October 2006, 08:12

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