Results 1 to 2 of 2

Thread: PyQt4 - Inserting data from array to QTableWidget

  1. #1
    Join Date
    Dec 2010
    Posts
    1
    Qt products
    Platforms
    Unix/X11 Windows

    Default PyQt4 - Inserting data from array to QTableWidget

    Hi all,

    I have a function which add a 2d array to a table. When I execute this function, a RuntimeError exception is thrown. Below is my code sample. I would be very thankful for any advice/assistance regarding this matter:

    Qt Code:
    1. def array_2_table(self, array, qtable):
    2. qtable.setColumnCount(10) #rows and columns of table
    3. qtable.setRowCount(600)
    4. for row in range(600): # add items from array to QTableWidget
    5. for column in range(10):
    6. item = array[row][column] # each item is a QTableWidgetItem
    7. # add the QTableWidgetItem to QTableWidget, but exception thrown
    8. qtable.setItem(row, column, QTableWidgetItem(item))
    To copy to clipboard, switch view to plain text mode 

    The exact exception is: RuntimeError: underlying C/C++ object has been deleted

    I would be very thankful if anyone could provide insight into this error or how one can add fixed-size 2D array to a QTableWidget.
    Thanks in advance,
    p.

  2. #2
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: PyQt4 - Inserting data from array to QTableWidget

    See if this will work:
    Qt Code:
    1. def array_2_table(self, array, qtable):
    2. qtable.setColumnCount(10)
    3. qtable.setRowCount(600)
    4. for row in range(600):
    5. for column in range(10):
    6. qtable.setItem(row,column,QTableWidgetItem(QString("%1").arg(array[row][column])))
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. QTableWidget - inserting data
    By Tomasz in forum Newbie
    Replies: 1
    Last Post: 29th September 2010, 14:32
  2. Inserting Items in QTableWidget
    By Ma7moud El-Naggar in forum Newbie
    Replies: 1
    Last Post: 30th August 2010, 13:17
  3. [PyQt4]C array to QImage
    By vasko_v_v in forum Newbie
    Replies: 1
    Last Post: 19th July 2009, 17:43
  4. Replies: 12
    Last Post: 28th April 2007, 20:25
  5. Problem inserting in QTableWidget
    By DPinLV in forum Qt Programming
    Replies: 2
    Last Post: 2nd August 2006, 00:10

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.