Bug report #17181

Crash using QgsComposerAttributeTableV2 after setting columns

Added by Loïc BARTOLETTI over 6 years ago. Updated over 6 years ago.

Status:Closed
Priority:Normal
Assignee:-
Category:Python bindings / sipify
Affected QGIS version:2.18.13 Regression?:No
Operating System: Easy fix?:No
Pull Request or Patch supplied:No Resolution:invalid
Crashes QGIS or corrupts data:Yes Copied to github as #:25080

Description

QGis crash when you use this code into the console (with a real project):

table = QgsComposerAttributeTableV2(iface.activeComposers()[0].composition(), False)
cols = table.columns()
newCol = QgsComposerTableColumn("test_for_crash")
newCol.setAttribute("$id")
cols.append(newCol)
table.setColumns(cols)
[i.heading() for i in table.columns()]

Tested on Windows 7 QGis 2.18, Debian QGis 2.14 and FreeBSD 2.18.

Seems to be a bad_alloc. Here some logs from Debian:

Warning: QObject::connect: Cannot connect (null)::layerModified() to QgsComposerAttributeTableV2::refreshAttributes()
Segmentation fault

FreeBSD show a windows with this error:

cxxrt::bad_alloc


Related issues

Related to QGIS Application - Bug report #17180: Atlas crash using python Closed 2017-09-21

History

#1 Updated by Giovanni Manghi over 6 years ago

  • Status changed from Open to Feedback

Is this related to #17180 ?

#2 Updated by Loïc BARTOLETTI over 6 years ago

No, they're different issues.
I'm working on several projects needing to use the composer and found these two bugs.

#3 Updated by Giovanni Manghi over 6 years ago

  • Status changed from Feedback to Open

Loïc BARTOLETTI wrote:

No, they're different issues.
I'm working on several projects needing to use the composer and found these two bugs.

thanks, so please add a description to #17180 just not leave the link to stackexchange, thanks.

#4 Updated by Jürgen Fischer over 6 years ago

#5 Updated by Denis Rouzaud over 6 years ago

  • Assignee deleted (Denis Rouzaud)

#6 Updated by Nyall Dawson over 6 years ago

  • Resolution set to invalid
  • Status changed from Open to Closed

Your code is a bit wrong:

cols = table.columns()
...
cols.append(newCol)
table.setColumns(cols)

table.columns() is returning a pointer to the table's columns, so any edits (such as appending columns) happens immediately. There's no need to call table.setColumns() after. This is causing the crash, because the table already has ownership of that columns object.

Admittedly, not the nicest api!

Also available in: Atom PDF