2

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?

Community
  • 1
  • 1
Iosif Spulber
  • 405
  • 3
  • 11
  • Is one address the widget and one the style-sheet? – mdurant Sep 18 '14 at 15:40
  • @mdurrant The "style-sheet" is just a string. And no, the address of the string would be a third, separate value. Besides, the warning claims "... of widget 0x1cbecc0"... – Iosif Spulber Sep 18 '14 at 15:46

1 Answers1

0

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
ekhumoro
  • 115,249
  • 20
  • 229
  • 336