PDA

View Full Version : Show new window on button click



jojanpm
29th November 2010, 08:12
How can i show a new window on button click of main window?

i tried this code in PyQt: (me doing in PyQt)

inside python class:

QtCore.QObject.connect(win.btnShow, QtCore.SIGNAL(_fromUtf8("clicked()")), self.showWin)

Then function,

def showWin(self):

app2 = QtGui.QApplication(sys.argv)
clsObj2 = AddShot.Ui_MainWindow()
win2 = QtGui.QMainWindow()
clsObj2.setupUi(win2)
win2.show()
app2.exec_()


No errors. But the window shows as a flash and goes!
Why this happens?

franz
29th November 2010, 12:51
1. Use code tags to improve readability.
2. Don't create a second QApplication. 1 is enough and all you need.
3. You should probably not create a second main window. Create a dialog instead.
4. Don't start a new event loop. It will lead to trouble (http://labs.qt.nokia.com/2010/02/23/unpredictable-exec/).