[PyQt] RE: Can I create more than one instance of a class?

Chris M chris.pm at gmail.com
Thu Jun 19 18:42:18 BST 2008


Adonay,

Glad to hear you have solved the issue :-D

The problem you give of the window disappearing or not appearing at
all is because the variable 'other' (or a,b,c) goes out of scope when
the _init_ method returns. You need to keep a reference to the window
object (which your new code does by using the global windowList). You
could also have defined the object as 'self.other' which would have
the same effect (although without a window list).

Regards,
Chris.

2008/6/19 adonay at k-demar.org <adonay at k-demar.org>:
> Finally using your code, the a b c window disappears!
> I have read a example of SDI window and now it works. If you are interested
> in, the code is like this.
>
> Parent program (main.py)
>
> class main(QMainWindow):
>    windowList=[]
>    def __init__(self):
>        QMainWindow.__init__(self)
>        uic.loadUi("ui/main.ui", self)
>        from new_window import newwindow
>        other = newwindow()
>        main.windowList.append(other)
>        other.show()
>
>
>
> Important code here is "main.windowList.append(other)" if you remove this
> line, child (other) never exists and never appears.
>
>
> Child window (new_window.py)
>
> class newwindow(QWidget):
>    def __init__(self):
>        QWidget.__init__(self)
>        uic.loadUi("ui/newwindow.ui", self)
>
>
>
> Tnx,
>
> Adonay Sanz
> www.k-demar.org
>
> --------------------------------------------------------------------
> mail2web LIVE – Free email based on Microsoft(R) Exchange technology -
> http://link.mail2web.com/LIVE
>
>
>
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>



More information about the PyQt mailing list