python - QWidget: Must construct a QApplication before a QPaintDevice error -


i know has been answered plenty of times, since i'm totally new pyqt/python (only been trying week now) can't seem implement of solutions in code.

import sys pyqt4.qtsql import * pyqt4 import qtcore, qtgui, uic  app = qtgui.qapplication(sys.argv)  class testapp(qtgui.qwidget):     def __init__(self):         qtgui.qwidget.__init__(self)          self.ui = uic.loadui("c:\python34\lib\site-packages\pyqt4\bazapodataka\database_gui.ui")         self.ui.show()   db = qsqldatabase.adddatabase("qpsql") db.sethostname("localhost") db.setdatabasename("bp za bolnicu") db.setusername("postgres") db.setpassword("zanoktica") db.setport(5432) ok = db.open()  if ok:     print("connected database") else:     print("error connecting database")  if __name__ == "__main__":     app = qtgui.qapplication(sys.argv)     win = testapp()     sys.exit(app.exec_()) 

i know code mess, i'm trying figure out multiple things @ once. made gui in qt designer, , i'm trying implement in main code can change please, , implement newer version.

you creating qapplication twice. delete first instantiation , move sql calls under second initialization


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -