How to terminate PyRoot+PyQt properly

From: Fine, Valeri <fine_at_bnl.gov>
Date: Thu, 27 Aug 2009 14:33:53 -0400

Hello,
I am trying to summarize the ROOT and qtRoot usage from afs. After when I hard coded the .rootrc file. I used the following lines:

ROOT.gEnv.SetValue("Gui.Backend","qt")
ROOT.gEnv.SetValue("Gui.Factory","qtgui")
ROOT.gEnv.SaveLevel(kEnvLocal);

my application is working fine! But I can not stop it. I think lastWindowClosed() slot is not comming!
I have the following lines:

  gLogger.debug('main')

  application = qApp
  terminator = ROOT.TQtRootSlot.CintSlot()   termAddress = sip.wrapinstance(ROOT.AddressOf(terminator)[0],QObject)   QObject.connect(application, SIGNAL("lastWindowClosed()"),termAddress ,SLOT("Terminate()"))
  from
Feicim.Gui.FeicimMainWidget import FeicimMainWidget
  mainWidget = FeicimMainWidget()
  mainWidget.show()
  mainWidget.start()
  ROOT.gApplication.Run(1)

If I coded ROOT.gApplication.Terminate() when I click in the File/Exit menu item, the application is crash.

You can check qtexample.py I attached the file. You can not exit the program without crash.
Can you help me?
Thanks!
Zoltan

import sys

from PyQt4.QtGui import *
from PyQt4.QtCore import *

import ROOT
import sip

class window(QMainWindow):

   def __init__(self):

       # Init the main window.
        QMainWindow.__init__(self)
        self.resize(350, 350)
  
     # Create the central widget.
        self.CentralWidget = QWidget(self)
        self.setCentralWidget(self.CentralWidget)
        self.Layout = QGridLayout(self.CentralWidget)
  

# Create a button.
self.QuitButton = QPushButton(self.centralWidget()) self.QuitButton.setText('Quit') self.Layout.addWidget(self.QuitButton, 1, 0)
# Connect the button.
QObject.connect(self.QuitButton, SIGNAL('clicked()'), self.quit)
# Create a root histogram.
self.hist = ROOT.TH1F("pipo","pipo", 100, 0, 100)
# Create the main TQtWidget (using sip to get the pointer to the central widget).
self.Address = sip.unwrapinstance(self.CentralWidget) self.Canvas = ROOT.TQtWidget(sip.voidptr(self.Address).ascobject())
# Place the TQtWidget in the main grid layout and draw the histogram.
self.Layout.addWidget(sip.wrapinstance(ROOT.AddressOf(self.Canvas)[0],QWidget), 0, 0) self.hist.Draw() def quit(self): print 'Bye bye...' self.close() ROOT.gApplication.Terminate()

if __name__ == '__main__':

   application = qApp
   terminator = ROOT.TQtRootSlot.CintSlot()    termAddress = sip.wrapinstance(ROOT.AddressOf(terminator)[0],QObject)    QObject.connect(application, SIGNAL("lastWindowClosed()"),termAddress ,SLOT("Terminate()"))    w = window()
   w.show()
   ROOT.gApplication.Run(1)
   print 'Bye forever!' Received on Thu Aug 27 2009 - 20:42:46 CEST

This archive was generated by hypermail 2.2.0 : Fri Aug 28 2009 - 05:50:04 CEST