Opened 11 years ago

Closed 11 years ago

#3236 closed bug (fixed)

Cannot determine the type of QgsComposerItem

Reported by: anitagraser Owned by: borysiasty
Priority: major: does not work as expected Milestone: Version 1.7.0
Component: Python plugins and bindings Version: Trunk
Keywords: Cc:
Must Fix for Release: No Platform: Debian
Platform Version: Awaiting user input: no


In Python console, type(item) will only return <class 'qgis.core.QgsComposerItem?'>

From IRC:

[09:49] <anita1> how can i get all QgsComposerLabels? from a composer? currently, i can just access all QgsComposerItems? but don't know how to filter only labels from them

[10:50] <marco> hi anita1

[10:50] <marco> dynamic cast in (C++) or query the class type (in python)

[10:51] <anita1> marco: hi. but that returns only QgsComposerItem?, not label

[10:51] <anita1> type(items[0]) <class 'qgis.core.QgsComposerItem?'>

[10:52] <marco> in python? Then there is probably missing a 'convertToSubclass' somewhere in the python bindings...

Attachments (1)

bug3236fix.diff (1.3 KB) - added by NathanW 11 years ago.
Attempted fix at bug

Download all attachments as: .zip

Change History (5)

comment:1 Changed 11 years ago by NathanW

I have added what is my attempt at fixing the bug, I gave it a run this morning and the types are returned correctly in Python however if you try and call any of the methods on the returned types you get a segfault. Eg calling .displayText() on a QgsComposerLabel? causes a segmentation fault. C and C++ aren't my normal programming languages, so I may have done something wrong or missed something.

Changed 11 years ago by NathanW

Attachment: bug3236fix.diff added

Attempted fix at bug

comment:2 Changed 11 years ago by mhugent

Thanks, NathanW! The patch is applied in r14736. I noticed those crashes too. The strange thing is it does not happen for items added via the python bindings, only for the already existing ones.

comment:3 Changed 11 years ago by NathanW

Thanks. I'm doing some testing now, not sure how much help it will be but if you cast in python using something like:

label = selectedComposerItems()[0] /* The first label on the composer */ label.class = qgis.core.qgscomposerlabel

You can call label.displayText() fine. The above will still crash sometimes even with the code I added to the SIP.

comment:4 Changed 11 years ago by wonder

Resolution: fixed
Status: newclosed

Fixed in r14766

Note: See TracTickets for help on using tickets.