[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyKDE] Problem with Destroy ???
From:       Boudewijn Rempt <boud () valdyas ! org>
Date:       2002-04-27 15:21:01
[Download RAW message or body]

On Thursday 25 April 2002 23:31, you wrote:
> Hello again...
> I don't know if this will help but if I add the destroy signal to the form,
> I get a core dump every time the form closes...
>

Well, I can run the pyuic generated Form1 class without any problems (using 
RC2). Even running the following doesn't present me with any problems, except 
for the message

Mutex destroy failure: Device or resource busy

When the second exec_loop finishes. I can imagine things going wrong; I don't
think QApplication is intended to be instantiated more than once from the
same application. If you want to run the dialog more than once from the same 
app, you shouldn't quit the app when the dialog is the only window and it 
closes. I can easily imagine that QApplication keeps a lot of state, even if 
the object seems to go out of scope: don't forget the global reference qApp:

boud@calcifer:~> python form.py
<qt.QApplication instance at 0x8166e24>
first
first
<qt.QApplication instance at 0x8166e24>
second
Mutex destroy failure: Device or resource busy
second
 
In short: don't try to instantiate QApplication twice. Use one QApplication 
that opens a dialog more than once.

Attached is my version of your script:
-- 
Boudewijn Rempt | http://www.valdyas.org
["form.py" (text/x-python)]

#!/usr/bin/python
#
import sys
from qt import *

from form1 import Form1

class App(Form1):
   def __init__(self, parent=None):
      Form1.__init__(self, parent)
      #self.db = connect()
      self.fieldlist = []
      self.dict = {}
      self.fields = ''
      self.result = '' 
      print qApp

   def PushButton1_clicked(self,*args):
      self.result = self.edit1.text() 
      print self.result
      self.close()

def prog():
   app = QApplication(sys.argv)
   QObject.connect(app, SIGNAL('lastWindowClosed()'),
                   app, SLOT('quit()'))
   win = App()
   app.setMainWidget(win)
   win.show()
   app.exec_loop()
   return win.result

if __name__ == '__main__':
   print prog()
   print prog()
#   app = QApplication(sys.argv)
#   QObject.connect(app, SIGNAL('lastWindowClosed()'),
#   app, SLOT('quit()'))
#   win = App()
#   app.setMainWidget(win)
#   win.show()
#   app.exec_loop()


["form1.py" (text/x-python)]

# Form implementation generated from reading ui file 'form1.ui'
#
# Created: Sat Apr 27 15:00:53 2002
#      by: The PyQt User Interface Compiler (pyuic)
#
# WARNING! All changes made in this file will be lost!


import sys
from qt import *


class Form1(QDialog):
    def __init__(self,parent = None,name = None,modal = 0,fl = 0):
        QDialog.__init__(self,parent,name,modal,fl)

        if name == None:
            self.setName("Form1")

        self.resize(321,181)
        self.setCaption(self.trUtf8("Form1"))


        self.TextLabel1 = QLabel(self,"TextLabel1")
        self.TextLabel1.setGeometry(QRect(20,30,65,20))
        self.TextLabel1.setText(self.trUtf8("TextLabel1"))

        self.edit1 = QLineEdit(self,"edit1")
        self.edit1.setGeometry(QRect(20,60,230,20))

        self.PushButton1 = QPushButton(self,"PushButton1")
        self.PushButton1.setGeometry(QRect(20,100,109,29))
        self.PushButton1.setText(self.trUtf8("PushButton1"))

        self.connect(self.PushButton1,SIGNAL("clicked()"),self.PushButton1_clicked)

    def PushButton1_clicked(self):
        print "Form1.PushButton1_clicked(): Not implemented yet"


if __name__ == "__main__":
    a = QApplication(sys.argv)
    QObject.connect(a,SIGNAL("lastWindowClosed()"),a,SLOT("quit()"))
    w = Form1()
    a.setMainWidget(w)
    w.show()
    a.exec_loop()


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic