我正在使用 PySide,当我尝试将电子表格设置为某个小部件时收到警告:
09-18 14:48:54,107 WARNING [D=0x7ff4a0074650:qt] Could not parse stylesheet of widget 0x1cbecc0
我已经查明了问题的位置并修复了它,但我惊讶地发现调用对象的地址setStyleSheet()
是不同的:
<views.hierarchy.TreeView object at 0x7f3ab8139440>
理想情况下,当我收到上面这样的警告时,我希望我可以像这样取消引用它here https://stackoverflow.com/questions/15011674/is-it-possible-to-dereference-variable-ids并了解更多有关原因的信息。
我的问题:
为什么两个地址不同?
有没有办法从小部件中获取警告中的地址
目的?
有没有办法直接取消引用警告中的地址?
看起来原始警告来自 Qt,因此消息中给出的小部件地址适用于底层 C++ 对象。您显示的另一条消息可能来自 python,因此显示 pyside 包装器对象的地址。
您可以使用芝博肯模块 https://pyside.github.io/docs/shiboken/shibokenmodule.html(或者SIP模块 http://pyqt.sourceforge.net/Docs/sip4/python_api.html对于 PyQt)来获取有关底层 C++ 对象的信息:
>>> 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
将此与气相色谱模块 https://docs.python.org/2/library/gc.html#module-gc,可以使用如下函数从 C++ 地址找到 python 包装对象:
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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)