Bug report #17181

Crash using QgsComposerAttributeTableV2 after setting columns

Added by Loïc BARTOLETTI 3 months ago. Updated 2 months 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

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 Open 09/21/2017

History

#1 Updated by Giovanni Manghi 3 months ago

  • Status changed from Open to Feedback

Is this related to #17180 ?

#2 Updated by Loïc BARTOLETTI 3 months 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 3 months 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 2 months ago

#5 Updated by Denis Rouzaud 2 months ago

  • Assignee deleted (Denis Rouzaud)

#6 Updated by Nyall Dawson 2 months 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