Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python PySide (Internal c++ Object Already Deleted)

Tags:

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?

like image 493
Johann du Toit Avatar asked Mar 17 '11 12:03

Johann du Toit


1 Answers

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:

Note: QMainWindow takes ownership of the widget pointer and deletes it at the appropriate time.

So to develop a Multi-Page application rather take a look at QStackedWidget.

like image 127
Johann du Toit Avatar answered Sep 23 '22 20:09

Johann du Toit