Python PySide(内部 c++ 对象已删除)
我最近决定使用 Python 和 PySide 编写我的第一个应用程序。但我有一个问题,希望你们能帮忙。
Python 不断引发“内部 C++ 对象”被删除的异常。根据我有限的 Python 经验,我认为我的对象超出了范围并被 Python 的垃圾收集器删除。
那么我将如何使用 PySide 在 Python 中设计多页面应用程序。并且能够保留我的 QWidget,以便我可以再次显示该页面。
感谢您抽出时间。
更新(代码)
instancing = None
def instance():
global instancing
if instancing == None:
instancing = WPZKernel()
return instancing
class WPZKernel:
win = None
mainscreen = None
def mainwindow(self):
if self.win == None:
self.win = GMKMainWindow(self)
return self.win
def main_panel(self):
if self.mainscreen == None:
self.mainscreen = GMKMainScreen(self.mainwindow())
return self.mainscreen
然后,我通常会通过调用以下命令来访问主面板:
import kernel
kernel.instance().main_panel()
那么我是否以错误的方式处理此问题?
I recently decided to write my first app with Python and PySide. But I have a problem and hope you guys can help.
Python keeps raising exceptions that the "Internal C++ Object" is deleted. From my limited experience with Python I figure that my object is going out of scope and being deleted by Python's Garbage Collector.
So how would I go about designing a multi-page application in Python with PySide. And being able to keep my QWidgets so I can show the page again.
Thanks for your time.
Update (Code)
instancing = None
def instance():
global instancing
if instancing == None:
instancing = WPZKernel()
return instancing
class WPZKernel:
win = None
mainscreen = None
def mainwindow(self):
if self.win == None:
self.win = GMKMainWindow(self)
return self.win
def main_panel(self):
if self.mainscreen == None:
self.mainscreen = GMKMainScreen(self.mainwindow())
return self.mainscreen
I would then normally access the mainpanel by calling:
import kernel
kernel.instance().main_panel()
So am I going about this the wrong way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
经过一番搜索和拉扯,我找到了解决方案。我通过将所有页面设置为中央小部件来显示所有页面,并在阅读 QMainWindow 文档< /a> 我发现我的小部件基本上被 qt 删除,如下所示:
因此,要开发多页面应用程序,请查看 QStackedWidget。
After some searching and hair pulling, I found the solution. I was showing all the pages by setting them as the central widget, and when reading the QMainWindow documentation I found that my widget basically gets deleted by qt as stated:
So to develop a Multi-Page application rather take a look at QStackedWidget.
请参阅此处:PySide 陷阱。
See here: PySide Pitfalls.