Tuesday 15 January 2013

python - Control not returning after self.close() encountered in PyQt -



python - Control not returning after self.close() encountered in PyQt -

i trying create ui using pyqt. has basic working. when script run on terminal, dialog box asking name should open , close when ok pressed. however, unable homecoming command qt app.

my code follows:

class interactive(qtgui.qwidget): def __init__(self): super(interactive,self).__init__() self.initgui() def initgui(self): self.setgeometry(300,300,290,150) self.setwindowtitle('input dialog') self.show() self.inputdialog = qtgui.qinputdialog() self.inputdialog.move(50,50) text, ok = self.inputdialog.gettext(self,'input dialog','enter name:') #self.text = text if ok: self.text = text print text self.close() if __name__ == "__main__": app = qtgui.qapplication(sys.argv) obj = interactive() #app.exec_() if app.exec_(): sys.exit() print "somerandomtext"

the print text within class working, test string "somerandomtext" not , programme not ending.

i have looked @ similar questions @ so, none seemed address same problem.do have create handler this?

normally, application quit automatically when lastly top-level window closes, preventedf happening in illustration because not allow event-loop started properly.

there numerous ways re-structure illustration avoid problem, simplest utilize timer this:

class interactive(qtgui.qwidget): def __init__(self): super(interactive,self).__init__() # delay initialization # self.initgui() ... if __name__ == "__main__": app = qtgui.qapplication(sys.argv) obj = interactive() qtcore.qtimer.singleshot(0, obj.initgui) app.exec_() print "somerandomtext"

ps:

the reason why deletelater() sort of works in other reply because posts deletion event event queue (which processed 1 time event-loop has started). close() method doesn't post event in way, , application doesn't chance quit automatically.

python qt pyqt pyqt4

No comments:

Post a Comment