Bug report #3236
Cannot determine the type of QgsComposerItem
|Affected QGIS version:||Regression?:||No|
|Operating System:||Debian||Easy fix?:||No|
|Pull Request or Patch supplied:||Resolution:||fixed|
|Crashes QGIS or corrupts data:||Copied to github as #:||13296|
In Python console, type(item) will only return <class 'qgis.core.QgsComposerItem'>
[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(itemsr0) <class 'qgis.core.QgsComposerItem'>
[10:52] <marco> in python? Then there is probably missing a 'convertToSubclass' somewhere in the python bindings...
#1 Updated by Nathan Woodrow almost 10 years ago
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.
#3 Updated by Nathan Woodrow almost 10 years ago
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()r0 /* 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.