Understanding the “underlying C/C++ object has been deleted” error

前端 未结 5 1776
故里飘歌
故里飘歌 2020-12-24 14:00

It\'s not the first time I am getting the RuntimeError: underlying C/C++ object has been deleted. I\'ve solved it many times altering my code in a random but in

5条回答
  •  庸人自扰
    2020-12-24 14:22

    How to test if the underlying object exists?

    How to avoid it?

    You could use:

    try: someObject.objectName()
    except RuntimeError: return False
    

    The .objectName() test is an arbitrary interrogation which all valid QObjects should easily pass.
    If they fail, they'll throw a RuntimeError which is an indication they are invalid.
    In this crude example we absorb the RuntimeError and instead return false.

提交回复
热议问题