pyqt4 Table Widget deleting c/c++ object

A

Andrew

I have two issues dealing with the table widget, though they may be
interconnected. I'm not sure. Both delete the cell widgets off of my
table but leave the rows, and then when I have the table update, it
complains the c++ object has been deleted.

# self.tableData.setCellWidget(rowCount, 0, trackItem)
# RuntimeError: underlying C/C++ object has been deleted

I have a list of a custom widget class that keeps track of several
directories. Each class gets put into a row on the table. I have a set
of radio buttons that will show me different views of the data: All,
New, Done, Errors, Warnings.
When I switch views, I clear my table, set the row count to 0, and
then add back in only the widgets I want to see.

Error 1:
I load in the data initially, and then repopulate the table, and then
re-size the window, instantly all listed rows are cleared, but the
rows stay. This only happened on the diagonal re-size (bottom left
corner); not the up and down, or side to side re-size. Attempting to
repopulate the table, resulted in: underlying C/C++ object has been
deleted. Though it will put in the correct number of rows required.

Everything worked fine as long as I did not re-size the window.

Error 2:
I load in the data initially, and then repopulate the table, the table
clears and then nothing happens. No error messages or even visible
rows. After several more repopulates it with either crash or tell me:
underlying C/C++ object has been deleted.

I had error 1 two days ago, then without changing the code, I now get
error 2. I do not have to re-size the window for it to break now.

I am using python 2.7 with PyQt4 4.7.7

Thanks for any insight,
Andrew
 
A

Andrew

I have two issues dealing with the table widget, though they may be
interconnected. I'm not sure. Both delete the cell widgets off of my
table but leave the rows, and then when I have the table update, it
complains the c++ object has been deleted.

# self.tableData.setCellWidget(rowCount, 0, trackItem)
# RuntimeError: underlying C/C++ object has been deleted

I have a list of a custom widget class that keeps track of several
directories. Each class gets put into a row on the table. I have a set
of radio buttons that will show me different views of the data: All,
New, Done, Errors, Warnings.
When I switch views, I clear my table, set the row count to 0, and
then add back in only the widgets I want to see.

Error 1:
I load in the data initially, and then repopulate the table, and then
re-size the window, instantly all listed rows are cleared, but the
rows stay. This only happened on the diagonal re-size (bottom left
corner); not the up and down, or side to side re-size. Attempting to
repopulate the table, resulted in: underlying C/C++ object has been
deleted. Though it will put in the correct number of rows required.

Everything worked fine as long as I did not re-size the window.

Error 2:
I load in the data initially, and then repopulate the table, the table
clears and then nothing happens. No error messages or even visible
rows. After several more repopulates it with either crash or tell me:
underlying C/C++ object has been deleted.

I had error 1 two days ago, then without changing the code, I now get
error 2. I do not have to re-size the window for it to break now.

I am using python 2.7 with PyQt4 4.7.7

Thanks for any insight,
Andrew

Here is a working example of what I'm describing above.

http://dl.dropbox.com/u/11715751/trackSetLoader.rar

Thanks.
 
D

David Boddie

I have two issues dealing with the table widget, though they may be
interconnected. I'm not sure. Both delete the cell widgets off of my
table but leave the rows, and then when I have the table update, it
complains the c++ object has been deleted.

# self.tableData.setCellWidget(rowCount, 0, trackItem)
# RuntimeError: underlying C/C++ object has been deleted

This is because you pass your widgets to this method and later ask
the table to clear the contents of the table. When it does so, it
deletes the underlying widgets, leaving only Python wrappers.

The documentation mentions that the table takes ownership of the
widget:

http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qtablewidget.html#setCellWidget
I have a list of a custom widget class that keeps track of several
directories. Each class gets put into a row on the table. I have a set
of radio buttons that will show me different views of the data: All,
New, Done, Errors, Warnings.
When I switch views, I clear my table, set the row count to 0, and
then add back in only the widgets I want to see.

Error 1:
I load in the data initially, and then repopulate the table, and then
re-size the window, instantly all listed rows are cleared, but the
rows stay. This only happened on the diagonal re-size (bottom left
corner); not the up and down, or side to side re-size. Attempting to
repopulate the table, resulted in: underlying C/C++ object has been
deleted. Though it will put in the correct number of rows required.

Everything worked fine as long as I did not re-size the window.

This may only be a symptom of the behaviour and not a guarantee that
the code was working correctly up until the point when the resize
occurred.
Error 2:
I load in the data initially, and then repopulate the table, the table
clears and then nothing happens. No error messages or even visible
rows. After several more repopulates it with either crash or tell me:
underlying C/C++ object has been deleted.

I had error 1 two days ago, then without changing the code, I now get
error 2. I do not have to re-size the window for it to break now.

I recommend that you create a list of non-widget data structures in
your parsePath() method and create widgets on the fly in your addToTable()
method. If you need to retain information when you repopulate the table
then update the data structures that correspond to the widgets just before
you clear the table.

David
 
A

Andrew

This is because you pass your widgets to this method and later ask
the table to clear the contents of the table. When it does so, it
deletes the underlying widgets, leaving only Python wrappers.

The documentation mentions that the table takes ownership of the
widget:

http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qtablewidg...
I had read that, but I did not fully understand what that actually was
supposed to mean. like a 'Ok it has ownership, good for it?' I hadn't
run into such a problem before either in any form. Now I know.
This may only be a symptom of the behaviour and not a guarantee that
the code was working correctly up until the point when the resize
occurred.



I recommend that you create a list of non-widget data structures in
your parsePath() method and create widgets on the fly in your addToTable()
method. If you need to retain information when you repopulate the table
then update the data structures that correspond to the widgets just before
you clear the table.

David

Thanks, it does work now that I've split it into a data and widget
class and create the widgets on the fly. Thanks for the help and sorry
for the delayed response.

Andrew
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,062
Latest member
OrderKetozenseACV

Latest Threads

Top