Issue
I'm using PySide and I get a warning when I try to set a spreadsheet to a certain widget:
09-18 14:48:54,107 WARNING [D=0x7ff4a0074650:qt] Could not parse stylesheet of widget 0x1cbecc0
I've pinpointed the location of the problem and fixed it, but I was surprised to see that the address of the object calling setStyleSheet()
is different:
<views.hierarchy.TreeView object at 0x7f3ab8139440>
Ideally, when I get warnings like the above I wish I could dereference it like here and find out more about the cause.
My questions:
Why are the two addresses different?
Is there any way to get the address in the warning from the widget object?
Is there any way to dereference the address in the warning directly?
Solution
It looks like the original warning is coming from Qt, and so the widget address given in the message is for the underlying C++ object. The other message you've shown is presumably from python, and therefore shows the address of the pyside wrapper object.
You can use the shiboken module (or the sip module for PyQt) to get information about the underlying C++ objects:
>>> import shiboken
>>> from PySide import QtGui
>>> app = QtGui.QApplication([])
>>> w = QtGui.QWidget()
>>> repr(w)
'<PySide.QtGui.QWidget object at 0x7f7398c1d950>'
>>> w.setStyleSheet('{')
Could not parse stylesheet of widget 0x12e2fc0
>>> print(shiboken.dump(w))
C++ address....... PySide.QtGui.QWidget/0x12e2fc0
hasOwnership...... 1
containsCppWrapper 1
validCppObject.... 1
wasCreatedByPython 1
>>> hex(shiboken.getCppPointer(w)[0])
>>> 0x12e2fc0
Combing this with the gc module, it is possible to find the python wrapper object from the C++ address with a function like this:
import gc, shiboken
def wrapper_from_address(address):
for item in gc.get_objects():
try:
if address == shiboken.getCppPointer(item)[0]:
return item
except TypeError:
pass
Answered By - ekhumoro
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.