[PyQt] difference between inits

Tobias Ramos tobalas at gmail.com
Wed Nov 12 16:46:20 GMT 2008


Hi all..i have some doubts about something is happening in my code. here is
it:

   w = window()
   f = QtCore.QFile(":/default.txt")
   f.open(QtCore.QIODevice.ReadOnly)
   model = TreeModel(QtCore.QString(f.readAll()))
   f.close()
   w.ui.lineEdit.setFocus()
   w.ui.treeView.setModel(model)
   w.show()

this works only in init code of application ex:

if __name__ == "__main__":
   app = QtGui.QApplication(sys.argv)
   w = window()
   f = QtCore.QFile(":/default.txt")
   f.open(QtCore.QIODevice.ReadOnly)
   model = TreeModel(QtCore.QString(f.readAll()))
   f.close()
   w.ui.lineEdit.setFocus()
   w.ui.treeView.setModel(model)
   w.show()
   sys.exit(app.exec_())

my question is.. why this not work:

class window(QtGui.QWidget,Ui_Form):

    def __init__(self,parent=None):
        QtGui.QWidget.__init__(self,parent)
        self.ui = Ui_Form()
        self.ui.setupUi(self)
        self.connect(self.ui.pushButton, QtCore.SIGNAL("clicked()"),
self.populaCombo)
         f = QtCore.QFile(":/default.txt")
         f.open(QtCore.QIODevice.ReadOnly)
         model = TreeModel(QtCore.QString(f.readAll()))
         f.close()
        self.ui.lineEdit.setFocus()
        self.ui.treeView.setModel(model)

when i put on __init__ of inherited class even the file is read..
thanks in advance.

Tobias
Belo Horizonte
Brasil
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20081112/f8b193f8/attachment.html


More information about the PyQt mailing list